Skip to content

Instantly share code, notes, and snippets.

@andrewminerd
Created October 7, 2011 18:33
Show Gist options
  • Save andrewminerd/1271030 to your computer and use it in GitHub Desktop.
Save andrewminerd/1271030 to your computer and use it in GitHub Desktop.
Accept-Language Header
<?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