Created
October 7, 2011 18:33
-
-
Save andrewminerd/1271030 to your computer and use it in GitHub Desktop.
Accept-Language Header
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 | |
$value = "en-us,en;q=0.7,ar-iq;q=0.3"; | |
$accepted = array(); | |
if (preg_match_all("/\s*([^,;]+)(?:;\s*q=([\d.]+))?/", $value, $m, PREG_SET_ORDER)) { | |
foreach ($m as $lang) { | |
$accepted[] = array( | |
'lang' => $lang[1], | |
'q' => isset($lang[2]) ? (float)$lang[2] : 1 | |
); | |
} | |
} | |
usort($accepted, function($l1, $l2) { | |
return ceil((float)$l2['q'] - (float)$l1['q']); | |
}); | |
var_dump($accepted); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment