Press "Enter" to skip to content

Compilation failed: support for \P, \p, and \X has not been compiled

首先感谢DiaHosting给我赞助了一个免费的VPS.
今天我终于把blog(WordPress)迁移到了新的VPS上, 由于环境的不一致(原来是Apache+mod_php, 现在是lighttpd+php_cgi), 中间出现不少问题, 但都没啥可说的.
一直到遇到如下这个问题:

Compilation failed: support for \P, \p, and \X has not been compiled
at offset 16 in /***/search-everything.php on line 802

该出的正则是:

  $postcontent = preg_replace(
           '"(?<!\<)(?<!\w)(\pL*'.$term.'\pL*)(?!\w|[^<>]*>)"i'
           , '<span class="search-everything-highlight-color"
style="background-color:'.$highlight_color.'">$1</span>'
           , $postcontent
           );

原来是在正则中使用了Unicode Properties \p{}
原因见:http://www.fredsantos.net/index.php?option=com_content&view=article&id=114:unicode-support-on-centos-52-with-php-and-pcre&catid=36:linux&Itemid=85
解决的办法也挺简单, 就是避开使用\p{L}(\pL是简写):

    $postcontent = preg_replace(
          '"(?<!\<)(?<!\w)([\x{41}-\x{5a}\x{61}-\x{7A}\x{0800}-\x{d7a3}]*'
. $term . '[\x{41}-\x{5a}\x{61}-\x{7A}\x{0800}-\x{d7a3}]*)(?!\w|[^<>]*>)"ui'
          , '<span class="search-everything-highlight-color"
style="background-color:'.$highlight_color.'">$1</span>'
          , $postcontent
          );

如上所示, 直接用Unicode的内码值来匹配, 摘取如上正则相关部分Unicode编码值分布说明如下:

\u4e00-\u9fa5 中文(CJK)
\u3130-\u318F 韩文
\uAC00-\uD7A3 韩文
\u0800-\u4e00 日文

BTW: GBK的编码值范围如下:

\x00-\xff GBK双字节编码范围
\x20-\x7f ASCII
\xa1-\xff 中文gb2312
\x80-\xff 中文 gbk

7 Comments

  1. jugos10.net
    jugos10.net September 17, 2017

    Buenas
    Estuve leyendo tu redaccion y hay muchas cosas que no sabia que me has enseñado, esta maravilloso..
    te queria devolver el periodo que dedicaste, con unas
    infinitas gracias, por preparar a gente como yo jujuju.
    Besos, saludos

  2. jugos10.net
    jugos10.net September 8, 2017

    🙂
    Que tiempo has dedicado a tremendo a porte y hay demasiadas cosas que
    no conocia que me has aclarado, esta maravilloso..
    te queria corresponder el tiempo que dedicaste, con unas infinitas gracias, por instruir a personas como yo jujuju.
    Saludos

  3. enjoy
    enjoy December 17, 2010

    看来这家的vps速度也不错,以后可以考虑购买。

  4. 雪候鸟
    雪候鸟 December 17, 2010

    @张二 除了内存小点以外, 其他的都还行. 速度快也是因为我用了super cache的缘故.

  5. 张二
    张二 December 17, 2010

    恩恩,看到了,以后买VPS就DiaHosting了,看样子速度很给力。

Comments are closed.