我在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);
有什么想法吗?谢谢!
答案 0 :(得分:2)
您需要在模式中添加未标记的标记U
:
preg_replace('#<a(.*)({pr_start})(.*)</a>#U',"START",$content);