【问题标题】:Can anyone explain this warning? [duplicate]谁能解释这个警告? [复制]
【发布时间】:2013-03-13 00:31:30
【问题描述】:

警告的含义是什么?

Warning: preg_replace() [function.preg-replace]: Compilation failed: PCRE does not support \L, \l, \N{name}, \U, or \u at offset 1 in

它是由这个函数触发的:

file_put_contents($file,preg_replace('(\uid=\d+)', 'uid=' . $uid, file_get_contents($file)));

即这种模式:

'(\uid=\d+)'

它可以在本地运行,但不能在线运行,这意味着它可能是我主机的 PHP 版本。我尝试用谷歌搜索解决方法,但找不到任何东西。

【问题讨论】:

  • 这是一个无效的模式。您忘记了分隔符,例如/(\uid.....
  • @MarcB - () 实际上是有效的分隔符。
  • @Marc B: () AFAIK 也是有效的分隔符。但是它会阻止你在模式中使用括号,所以它通常不是一个好的选择。
  • 你想和\u匹配什么?
  • @ÁlvaroG.Vicario:seesh,php 需要更新他们的文档。文本谈论括号,但示例使用{}。去搞清楚。谢谢...

标签: php


【解决方案1】:

PCRE 不支持\u espace 序列。

换句话说,您的正则表达式不正确。改用(uid=\d+) 之类的方法。

正如 cmets 中所说(感谢 Mellamokb),这里是 source

想知道\u是什么,可以看here

\u 大写下一个字符。不在 [ ] 中。

【讨论】:

【解决方案2】:
file_put_contents($file,preg_replace('/uid=\d+/', 'uid=' . $uid, file_get_contents($file)));

【讨论】:

    【解决方案3】:

    RegExp 模式应以/ 分隔符为界,您也可以使用(#~)。此外,没有转义序列\u。你可能想试试这个 -

    preg_replace('/\\uid=\d+/', 'uid=' . $uid, file_get_contents($file))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-16
      • 1970-01-01
      • 1970-01-01
      • 2012-06-21
      • 1970-01-01
      • 1970-01-01
      • 2021-01-08
      • 2012-02-12
      相关资源
      最近更新 更多