Mercurial > SimpleWebPresenter
comparison accept-language.inc @ 0:d2da64705bce
Refactored everything in the CMS into this repos.
| author | Tom Fredrik "BFG" Klaussen <bfg@blenning.no> |
|---|---|
| date | Tue, 10 May 2011 14:01:34 +0200 |
| parents | |
| children | 60e73809887a |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:d2da64705bce |
|---|---|
| 1 <?php | |
| 2 function acceptedLanguages() { | |
| 3 $langs = array(); | |
| 4 | |
| 5 if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { | |
| 6 // break up string into pieces (languages and q factors) | |
| 7 preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse); | |
| 8 | |
| 9 if (count($lang_parse[1])) { | |
| 10 // create a list like "en" => 0.8 | |
| 11 $langs = array_combine($lang_parse[1], $lang_parse[4]); | |
| 12 | |
| 13 // set default to 1 for any without q factor | |
| 14 foreach ($langs as $lang => $val) { | |
| 15 if ($val === '') $langs[$lang] = 1; | |
| 16 } | |
| 17 | |
| 18 // sort list based on value | |
| 19 arsort($langs, SORT_NUMERIC); | |
| 20 } | |
| 21 return $langs; | |
| 22 } | |
| 23 } | |
| 24 ?> |
