在php中使用preg_replace和regex

时间:2013-10-04 12:27:45

标签: php regex

我在PHP中有这个字符串

$content="<a some_text> {pr_start} some_text</a> <a other_text>{pr_stop}</a>
          <a some_text> {pr_start} </a> <a some_text> {pr_start} </a>";

我想替换所有出现的子串

"<a some_text> {pr_start}  some_text</a>"

带有文字"START",其余部分保持不变!

预期结果是:

"START <a other_text>{pr_stop}</a> START START"

我用过

preg_replace('#<a(.*)({pr_start})(.*)</a>#',"START",$content);

有什么想法吗?谢谢!

1 个答案:

答案 0 :(得分:2)

您需要在模式中添加未标记的标记U

preg_replace('#<a(.*)({pr_start})(.*)</a>#U',"START",$content);