note 90592 deleted from reserved.variables.server by cmb
| From: | cmb@php.net | Date: | Sun, 28 Jul 2019 08:03:12 +0000 |
| Subject: | note 90592 deleted from reserved.variables.server by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-211711@lists.php.net to get a copy of this message | ||
Note Submitter: dragon[dot]dionysius[at]gmail[dot]com
----
I've updated the function of my previous poster and putted it into my class.
<?php
/**
* Checking HTTP-Header for language
* needed for various system classes
*
* @return boolean true/false
*/
private function _checkClientLanguage()
{
$langcode = (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) ?
$_SERVER['HTTP_ACCEPT_LANGUAGE'] : '';
$langcode = (!empty($langcode)) ? explode(";", $langcode) : $langcode;
$langcode = (!empty($langcode['0'])) ? explode(",",
$langcode['0']) : $langcode;
$langcode = (!empty($langcode['0'])) ? explode("-",
$langcode['0']) : $langcode;
return $langcode['0'];
}
?>
Please note, you have to check additional the result! Because the header may be missing or another
possible thing, it is malformed. So check the result with a list with languages you support and
perhaps you have to load a default language.
<?php
// if result isn't one of my defined languages
if(!in_array($lang, $language_list)) {
$lang = $language_default; // load default
?>
My HTTP_ACCEPT_LANGUAGE string:
FF3: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
IE7: de-ch
So, take care of it!