0

我在 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);

任何想法?谢谢!

4

1 回答 1

2

您需要U在模式中添加一个不贪婪的标志:

preg_replace('#<a(.*)({pr_start})(.*)</a>#U',"START",$content);
于 2013-10-04T12:35:32.227 回答