PHP:RegEx与ctype_ *

时间:2009-12-20 18:10:42

标签: php regex localization

几个月前,you为我的IsAlpha& amp;提供了完美的解决方案。合作问题。但是再一次,我在升级PHP(到版本5.2.9)之后遇到了问题,尽管ctype_ *函数现在似乎已经完成了它们的工作:

ctype_alpha( $value ) /* VS */ preg_match("/^[\p{L} _.\-]+$/u",    $value)

ctype_alnum( $value ) /* VS */ preg_match("/^[\p{L}0-9 _.\-]+$/u", $value)

根据问题,我的意思是'GB'或'blablue'即ctype_alpha()正确识别为alpha,但preg_match("/^[\p{L} _.\-]+$/u", $value)失败。

如果您有任何想法,请告诉我,经过一些严肃的谷歌搜索后我用完了。

很多,非常感谢!

P.S。 LANG / LC_CTYPE / etc在两个环境中都设置为en_US.UTF-8

2 个答案:

答案 0 :(得分:4)

确保已使用UTF-8支持以及Unicode属性支持编译PCRE。

if ( ! @preg_match('/^.$/u', 'ñ'))
    echo 'PCRE has not been compiled with UTF-8 support.';

if ( ! @preg_match('/^\pL$/u', 'ñ'))
    echo 'PCRE has not been compiled with Unicode property support.';

来自http://github.com/kohana/kohana/blob/master/install.php的检查。

答案 1 :(得分:-1)

我在托管服务器上使用unicode元字符的正则表达式存在一些问题。简而言之:它不起作用。我没有调查真正的原因,因为它是一个临时服务器,但你可能会考虑unicode支持,因为你的问题似乎很相似。