php多语言简单实现办法

语言包:

if(isset($_GET['lang'])) {
$l = $_GET['lang'];
} else {
$l = getenv('HTTP_ACCEPT_LANGUAGE');
$l = strtolower(substr($l,0,2));
}
$l = ($l == 'zh' || $l == 'en') ? $l : 'cn';

$lang = array();
$lang['en'][0] = 'php simple implementation of multi-language approach abc';
$lang['zh'][0] = 'php多語言簡單實現辦法';
$lang['cn'][0] = 'php多语言简单实现办法';

模板:

echo $lang[$l][0];

请求:
http://localhost/?lang=cn

转载请注明出处:https://www.onexin.net/php-simple-implementation-of-multi-language-approach/

随机文章:

1、PHP设计模式(四)—原型模式(Prototype Pattern)
https://www.onexin.net/php-prototype-pattern/

2、只需花一块钱买一个月阿里云主机
https://www.onexin.net/just-spend-a-money-to-buy-a-month-ali-cloud-host/

3、PHP 7.4新特性箭头函数 2.0 (简短闭包)
https://www.onexin.net/php-7_4-fn-use/

4、SEO工具,站长必备
https://www.onexin.net/seo-tools-for-owners-must-have/

5、wp的get_file_data获取css文件申明信息
https://www.onexin.net/wp-get_file_data-css/

Leave a Reply