2

locale

locale
SYNOPSIS

locale()

DESCRIPTION
CODE
  1. function locale() {
  2.     if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
  3.         return false;
  4.     }
  5.  
  6.     $httplanguages = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  7.  
  8.     if (empty($httplanguages) === true) {
  9.         return false;
  10.     }
  11.  
  12.     $lang = false;
  13.     $quality = 0.0;
  14.  
  15.     $accepted = preg_split('/,\s*/', $httplanguages);
  16.  
  17.     foreach ($accepted as $accept) {
  18.         $match = null;
  19.         $result = preg_match('/^([a-z]{1,8}(?:[-_][a-z]{1,8})*)(?:;\s*q=(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3})?))?$/i', $accept, $match);
  20.  
  21.         if ($result < 1) {
  22.             continue;
  23.         }
  24.  
  25.         $q = isset($match[2]) ? (float) $match[2] : 1.0;
  26.  
  27.         if ($q > $quality) {
  28.             $quality = $q;
  29.  
  30.             $lang = current(explode('_', current(explode('-', $match[1]))));
  31.  
  32.             if ($quality == 1.0) {
  33.                 break;
  34.             }
  35.         }
  36.     }
  37.  
  38.     return $lang;
  39. }
SEE ALSO

engine

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

===

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].