Heim >Backend-Entwicklung >PHP-Tutorial > php preg_replace求解,该如何解决
php preg_replace求解
如题,有一段文本
123456abcdefgsdfsdafdfabcdffsafd
目标:将第二次出现的abc进行替换,第一次不做操作
菜鸟求解
<br /> <br /> <?php <br /> <br /> $str = '<p>元<a target="_blank" href="http://www.trjcn.com/news/news--type-list/cid-21/industry_id-14.html">半导体材料</a><a target="_blank" href="http://www.trjcn.com/news/news--type-list/cid-21/industry_id-14.html">半导体</a>制造厂,导体导体导体导体导体<a target="_blank" href="http://www.trjcn.com/news/news--type-list/cid-21/industry_id-14.html">半导体</a></p>';<br /> <br /> <br /> $str = preg_replace('/(导体)(?!(:?[^<]<br><font color='#FF8000'>------解决方案--------------------</font><br><(?!a)[^>]*>)*<\/a>)/imu', '<a>$1</a>', $str);<br /> <br /> echo $str;<br /> <br /> <br />