PCRE是使用utf-8支持编译的,但不支持它

时间:2013-10-02 08:36:35

标签: php pcre

虽然我服务器中pcretest -C的结果表明pcre支持utf8,但即使输入匹配的模式,以下代码也总是返回false,并且它似乎无法识别utf-8字符:< / p>

   $pattern = '/^\x{06F0}?\x{06F9}\d{9}$/u';
   if (!preg_match($pattern, $value)) { // $value is a function parameter
      return false;
   }
   return true;

pcretest -C的输出:

PCRE version 7.8 2008-09-05
Compiled with
  UTF-8 support
  Unicode properties support
  Newline sequence is LF
  \R matches all Unicode newlines
  Internal link size = 2
  POSIX malloc threshold = 10
  Default match limit = 10000000
  Default recursion depth limit = 10000000
  Match recursion uses stack

PHP版本:5.3.2

此代码在我的localhost中按预期工作。

有什么建议吗?

1 个答案:

答案 0 :(得分:2)

在这里工作(注意html_entity_decode的charset默认值在PHP 5.4中更改为UTF-8):

$ cat a.php
<?php
$pattern = '/^\x{06F0}?\x{06F9}\d{9}$/u';
var_dump(preg_match($pattern, html_entity_decode('&#x6F9;123456789')));
$ php a.php 
int(1)

请注意,默认情况下,PHP不使用系统PCRE库(尽管很多发行版,出于显而易见的原因,使用系统PCRE库)。输入php -i并查找PCRE部分以获取有关二进制文件使用版本的更多信息。

相关问题