duanjianao0592 2010-04-23 17:25
浏览 66
已采纳

PHP PCRE在测试和托管服务器上的差异

I've got the following regular expression that works fine on my testing server, but just returns an empty string on my hosted server.

$text = preg_replace('~[^\\pL\d]+~u', $use, $text);

Now I'm pretty sure this comes down to the hosting server version of PCRE not being compiled with Unicode property support enabled. The differences in the two versions are as follows:

My server:

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

Hosting server:

PCRE version 4.5 01-December-2003
Compiled with
UTF-8 support
Newline character is LF
Internal link size = 2
POSIX malloc threshold = 10
Default match limit = 10000000
Match recursion uses stack

Also note that the version on the hosting server (the same version PHP is compiled against) is pretty old.

What confuses me though, is that pcretest fails on both servers from the command line with

re> ~[^\\pL\d]+~u
** Unknown option 'u'

although this regexp works fine when run from PHP on my server.

So, I guess my questions are does the regular expression fail on the hosting server because of the lack of Unicode properties? Or is there something else that I'm missing?

Thanks all, Gaz.

  • 写回答

3条回答 默认 最新

  • duanmei9980 2010-04-24 05:04
    关注

    PCRE 4.5 does support UTF-8 but does not support Unicode properties such as \pL and does not support the /u flag that enables them. You'll need to upgrade PCRE on your server to version 5.0 or later. You may also need to upgrade PHP to have support for /u in preg_replace().

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝