Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function printFormat($var){
- echo str_replace(array(" ","\n"), array(" ","<br>"), print_r($var,true))."<br>";
- }
- function language_by_q($simpleLang = true){
- $primary = array();
- $accept = explode(",",$_SERVER["HTTP_ACCEPT_LANGUAGE"]);
- for($i = 0; $i < count($accept); $i++){
- $lang = explode(";", $accept[$i]);
- $q = 1;
- if(isset($lang[1])){
- $pos = strpos($lang[1], "=");
- if($pos !== false)
- $q = floatval(substr($lang[1], $pos + 1));
- }
- if($simpleLang){
- $pos = strpos($lang[0], "-");
- if($pos !== false)
- $lang[0] = substr($lang[0], 0, $pos);
- }
- if(in_array($q, $primary))
- $q -= 0.001;
- if(isset($primary[$lang[0]]))
- continue;
- $primary[$lang[0]] = $q;
- }
- arsort($primary,SORT_NUMERIC);
- return $primary;
- }
- echo "Jazyky od prohlížeče: <br>";
- printFormat($_SERVER["HTTP_ACCEPT_LANGUAGE"]);
- /* Příklad: cs,en-GB;q=0.8,en;q=0.6 */
- echo "<br>Vybrán jen hlavní jazyk<br>";
- printFormat(language_by_q());
- /* Příklad: Array
- (
- [cs] => 1
- [en] => 0.8
- ) */
- echo "<br>Vybrány lokalizace jazyků<br>";
- printFormat(language_by_q(false));
- /* Příklad: Array
- (
- [cs] => 1
- [en-GB] => 0.8
- [en] => 0.6
- ) */
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement