开发者

PHP ctype_print - different behavior on Windows and Linux?

I just experienced a weird problem today:

On my windows machine, ctype_print("äöütest") returned true.

But when I was on my linux machine (debian), it returned false.

In the php.net documentation I read that the locale set might be affecting this. How can I change that?

Edit: Indeed - when I run

setlocale(LC_ALL, null)

on my local machine I get

German_Germany.1252

开发者_JAVA百科On the server I get

C

What would be a sensible default value?


something like this i guess

  // 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');
    }

for setting to 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');
?>

where directory structure of locale is (for example) : locale/fr_FR/LC_MESSAGES/mydomain.mo locale/en_US/LC_MESSAGES/mydomain.mo

and ABSPATH is the absolute path to the locale dir

further note, under linux systems, it seems to be necessary to create the locale at os level using 'locale-gen'.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜