【问题标题】:Does using /u modifier in PCRE cause any problemm if unicode is not used?如果不使用 unicode,在 PCRE 中使用 /a 修饰符会导致任何问题吗?
【发布时间】:2013-09-18 12:41:20
【问题描述】:

/u 修饰符用于 PCRE 中,当我们使用像 /x{0xFF0} 这样的 unicode 字符时。

如果我们有像/^\d{10}$/u 这样的正则表达式(例如,在正则表达式中不使用 unicode 时使用 unicode 修饰符),它会导致任何问题吗?我问这个是因为我在 localhost 和生产服务器中得到不同的结果(使用 preg_match 函数)

如果没有问题,为什么默认不使用这个修饰符?

【问题讨论】:

  • 应该不会有问题,因为ASCII是utf-8的子集;并且默认情况下不使用它,因为它在性能方面成本更高......但也因为底层 pcre 可能不支持它(stackoverflow.com/questions/4509576/…

标签: php pcre


【解决方案1】:

它不会导致任何问题,因为 ascii 字符是 utf-8 的一部分,只是要小心,因为“u”修饰符取决于使用 --enable-utf8 编译的 PCRE。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-21
    • 2014-04-05
    • 2017-08-16
    • 1970-01-01
    • 2020-01-28
    • 2021-12-15
    • 1970-01-01
    • 2019-10-03
    相关资源
    最近更新 更多