2012-09-18 38 views
2

我有几个在文本文档中,这些标签与很多其他的内容,以及(存储在$内容):PHP的preg_replace certrain串

[[tag:author|id:6329]] 

而且我一直在试图取代所有这些带有给定id的标签(在本例中为6329)和另一个字符串。

$id = 6329; 
$replacement = $this->format($id); 
$pattern = "/(\[\[tag:author|id:".$id."\]\])/"; 
preg_replace($pattern, $replacement, $content); 

尽管这看起来不起作用,并且在过去的几个小时里我一直在撕掉我的头发。任何人都可以看到错误?非常感谢。

回答

1

您也需要转义|,不需要用()包装它。

尝试:

$pattern = "/\[\[tag:author\|id:".$id."\]\]/"; 
+0

你是真棒。 – frigg