Last active
December 19, 2015 13:59
-
-
Save woodworker/5965823 to your computer and use it in GitHub Desktop.
simple accept header parser
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
<?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