This is a very simple class that can determine the idiom and country of the user browser.
It analyzes the HTTP request header Accept-Language and parses it to obtain the idiom and the country used in the browser accessing the current script page.
The idiom and the country are returned in class variables.- <?
- class HTTPLocale
- {
- var $language;
- var $country;
- function HTTPLocale()
- {
- $data = array_map("trim", explode(",", $_SERVER["HTTP_ACCEPT_LANGUAGE"]));
- $data = array_map("trim", explode(";", $data[0]));
- $data = array_map("trim", explode("-", $data[0])); //get first pair of language-country
-
- $this->language = strtoupper($data[0]);
- $this->country = strtoupper($data[1]);
- }
- }
- ?>
复制代码 http://www.phpclasses.org/browse/package/3734.html
another:
http://www.phpclasses.org/browse/package/3846.html |