Skip to content

Instantly share code, notes, and snippets.

@dragonmantank
Created March 15, 2011 18:12
Show Gist options
  • Save dragonmantank/871168 to your computer and use it in GitHub Desktop.
Save dragonmantank/871168 to your computer and use it in GitHub Desktop.
Parses accept headers based on preference
/**
* 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