Skip to content

Instantly share code, notes, and snippets.

@woodworker
Last active December 19, 2015 13:59
Show Gist options
  • Save woodworker/5965823 to your computer and use it in GitHub Desktop.
Save woodworker/5965823 to your computer and use it in GitHub Desktop.
simple accept header parser
<?php
function parseHttpAcceptHeader($string) {
$pattern = '#(?P<maintype>[a-z\*]*)/(?P<fullsubtype>(?P<subtype>[a-z0-9.\*-]*)([+](?P<submediatype>[a-z]*))?)(;q=(?P<quality>[0-9.]*))?#i';
preg_match($pattern, $string, $matches);
return $matches;
}
$string = 'application/vnd.github.full+json;q=0.8';
var_dump(parseHttpAcceptHeader($string));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment