[英]Using preg_replace and regex in php
I have this string in PHP 我在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>";
I want to replace all the occurrences of the substring 我想替换所有出现的子字符串
"<a some_text> {pr_start} some_text</a>"
with text "START"
and leave the rest as it is! 输入文字
"START"
,其余内容保持不变!
The result expected is: 预期的结果是:
"START <a other_text>{pr_stop}</a> START START"
I used 我用了
preg_replace('#<a(.*)({pr_start})(.*)</a>#',"START",$content);
Any idea? 任何想法? Thanks!
谢谢!
您需要在模式中添加一个不愉快的标志U
:
preg_replace('#<a(.*)({pr_start})(.*)</a>#U',"START",$content);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.