php preg_replace求解,该如何解决

WBOY
Release: 2016-06-13 12:49:29
Original
784 people have browsed it

php preg_replace求解
如题,有一段文本
123456abcdefgsdfsdafdfabcdffsafd

目标:将第二次出现的abc进行替换,第一次不做操作
菜鸟求解


------解决方案--------------------
$str = '123456abcdefgabceeesdfsdafdfabcdffsafdabcdefg';

$str = preg_replace('/(?))abc/iU', '---', $str);

echo $str,'
';

只适用于有且仅有标签
------解决方案--------------------
<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 />
Copy after login


。。。。。。这个才是
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!