Press "Enter" to skip to content

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

First, thanks to DiaHosting for sponsoring me a free VPS.
Today I finally migrated the blog (WordPress) to the new VPS. Due to the inconsistent environment (previously Apache+mod_php, now lighttpd+php_cgi), a number of problems came up along the way, but none worth dwelling on.
Until I ran into the following problem:

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

The regex in question is:

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

It turns out the regex uses Unicode Properties \p{}
The reason is explained at: 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
The fix is also pretty simple — just avoid using \p{L} (\pL is the shorthand):

    $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
          );

As shown above, match directly using the Unicode code points. The distribution of the Unicode code-point ranges relevant to the regex above is as follows:

\x{4e00}-\x{9fa5} Chinese (CJK)
\x{3130}-\x{318F} Korean
\x{AC00}-\x{D7A3} Korean
\x{0800}-\x{4e00} Japanese

BTW: The GBK encoding value ranges are as follows:

\x00-\xff GBK double-byte encoding range
\x20-\x7f ASCII
\xa1-\xff Chinese gb2312
\x80-\xff Chinese gbk

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.