2011-02-03 65 views
1

我剛剛經歷了一個奇怪的問題今天:PHP ctype_print - 在Windows和Linux上的不同行爲?

在我的Windows機器上,ctype_print(「äöütest」)返回true。

但是當我在我的Linux機器上(debian),它返回false。

在php.net文檔中,我讀到區域設置可能會影響到這一點。 我該如何改變?

編輯:事實上 - 當我在我的本地機器上運行

setlocale(LC_ALL, null) 

我得到

German_Germany.1252

在服務器上,我得到

C

什麼是合理的默認值?

回答

3

像這樣我想

// 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級別創建語言環境。

+0

好的,但如果我想要整個UTF8字符集?或者這真的只是一個區域代碼,我必須選擇一個? – 2011-02-03 15:33:35

相關問題