2013-03-12 85 views
1

警告的含义是什么?任何人都可以解释此警告?

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的我的主机的版本。我试图谷歌解决方法,但找不到任何东西。

+0

这是一个无效的模式。您忘记了分隔符,例如'/(\ uid ....'。 – 2013-03-12 16:20:24

+0

@MarcB - '()'实际上是有效的分隔符 – 2013-03-12 16:21:33

+0

@Marc B:'('和')'也是有效的分隔符AFAIK。但它阻止你使用括号 – 2013-03-12 16:21:57

回答

5

PCRE不支持\u espace序列。

换句话说,你的正则表达式是不正确的。改为尝试类似(uid=\d+)

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

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

\ü标题字符一个字符。不在[]中。

+0

+1资料来源:http://www.php.net/manual/en/reference.pcre.pattern。 differences.php,#5。 – mellamokb 2013-03-12 16:20:45

+0

第一次工作!谢谢大家。 – Starkers 2013-03-12 16:25:51

+0

@JWH不客气。正则表达式总是有点棘手,当你不习惯他们:) – Geoffroy 2013-03-12 16:26:57

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

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

preg_replace('/\\uid=\d+/', 'uid=' . $uid, file_get_contents($file)) 
相关问题