找回密码
 新猫注册
查看: 673|回复: 0

HTTPLocale.class.php

[复制链接]
kernel 发表于 2008-10-14 20:34:56 | 显示全部楼层 |阅读模式
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.
  1. <?
  2. class HTTPLocale
  3. {
  4.   var $language;
  5.   var $country;

  6.   function HTTPLocale()
  7.   {
  8.     $data = array_map("trim", explode(",", $_SERVER["HTTP_ACCEPT_LANGUAGE"]));
  9.     $data = array_map("trim", explode(";", $data[0]));
  10.     $data = array_map("trim", explode("-", $data[0])); //get first pair of language-country
  11.    
  12.     $this->language = strtoupper($data[0]);
  13.     $this->country  = strtoupper($data[1]);
  14.   }
  15. }

  16. ?>
复制代码
http://www.phpclasses.org/browse/package/3734.html

another:

http://www.phpclasses.org/browse/package/3846.html
您需要登录后才可以回帖 登录 | 新猫注册

本版积分规则

手机版|小黑屋|[漫猫]动漫论坛

GMT+8, 2024-11-21 21:27

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表