2011-02-03 60 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

相关问题