Created
March 15, 2011 18:12
-
-
Save dragonmantank/871168 to your computer and use it in GitHub Desktop.
Parses accept headers based on preference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns the Accept options that the client requested | |
* This array is seperated by the precedence that the client requested as well. | |
* @param string $rawOptions Accept options from the header | |
* @return array | |
*/ | |
function getAcceptOptions($rawOptions) { | |
$options = explode(',', $rawOptions); | |
$accept = array(); | |
foreach ($options as $option) { | |
if (strpos($option, ';')) { | |
list($type, $pref) = explode(';', $option); | |
list(, $pref) = explode('=', $pref); | |
$accept[(string) $pref][] = $type; | |
} else { | |
$accept[1][] = $option; | |
} | |
} | |
return $accept; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment