Detect if PCRE was built without the --enable-unicode-properties or --enable-utf8 configuration switches

前端 未结 2 1791
悲&欢浪女
悲&欢浪女 2020-12-17 15:30

I\'ve a PHP library that uses a number of regular expressions featuring the \\P expressions for multibyte strings, e.g.

((((?:\\P{M}\\p{M}*)+?)|         


        
相关标签:
2条回答
  • 2020-12-17 16:09

    While comments suggest checking for PREG_BAD_UTF8_ERROR the PHP source http://lxr.php.net/xref/PHP_5_6/ext/pcre/php_pcre.c#141 suggests this constant is always available if PCRE is. Indeed it seems --enable-unicode-properties is a PCRE lib switch and is simply not exposed by PHP. The only thing I can imagine is running a simple regexp once with warning supressed...

    0 讨论(0)
  • 2020-12-17 16:26

    Other than trying it, I think the only way is to use the pcretest command line tool, with the -C option (compile-time options):

    bash-4.1.5$ pcretest -C
       No UTF-8 support
       No 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
    
    0 讨论(0)
提交回复
热议问题