像這樣我想
// set locale encoding ISO-8859-2
// pl_PL for Linux
// polish_Poland.28592 for Windows
if (PHP_OS == 'WINNT') {
setlocale(LC_ALL, 'polish_Poland.28592');
} else {
setlocale(LC_ALL, 'pl_PL');
}
用於設置成UTF-8
<?php
$codeset = "UTF8"; // warning ! not UTF-8 with dash '-'
// for windows compatibility (e.g. xampp) : theses 3 lines are useless for linux systems
putenv('LANG='.$lang.'.'.$codeset);
putenv('LANGUAGE='.$lang.'.'.$codeset);
bind_textdomain_codeset('mydomain', $codeset);
// set locale
bindtextdomain('mydomain', ABSPATH.'/locale/');
setlocale(LC_ALL, $lang.'.'.$codeset);
textdomain('mydomain');
?>
其中locale的目錄結構是(舉例來說): 區域設置/ fr_FR目錄/ LC_MESSAGES/mydomain.mo locale/en_US/LC_MESSAGES/mydomain.mo
和ABSPATH是區域設置目錄的絕對路徑
進一步說明,在linux系統下,似乎有必要使用'locale-gen'在os級別創建語言環境。
好的,但如果我想要整個UTF8字符集?或者這真的只是一個區域代碼,我必須選擇一個? – 2011-02-03 15:33:35