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

Leave a Reply