php正则替换有关问题

WBOY
Release: 2016-06-13 12:07:24
Original
1009 people have browsed it

php正则替换问题

//1,如何去掉出现“微信号”及紧邻的标签对,如下代码中去掉这块内容:<div>这里有很多其他字符、表单等等....微信号...这里有很多其他字符、表单等等</div><br />		$content	= "0000<div>111<div>222<div>这里有很多其他字符、表单等等....微信号...这里有很多其他字符、表单等等</div>222</div>111</div>0000";<br />		<br />		//2,如何去掉出现qrcode_for_gh_2ff16e7c9789_258.jpg的图片<br />		$content	= '<img   style="max-width:90%" title="" alt="" src="http://www.aabbcc.com/upload/kdidd08983.jpg"><img   style="max-width:90%" title="" alt="" src="http://www.aabbcc.com/upload/qrcode_for_gh_2ff16e7c9789_258.jpg">';<br />		// $content	= preg_replace('/<img (.*?)src=["\']http[s]?:\/\/www\.aabbcc\.com\/upload\/qrcode_for_gh_2ff16e7c9789_258\.jpg["\'](.*?) alt="php正则替换有关问题" >/is', '', $content);<br />		var_dump( $content );
Copy after login

------解决思路----------------------
1、echo preg_replace('/<[^>]+>[^<>]*微信号[^<>]*<[^>]+>/u', '', $content);<br /><br />2、$content    = preg_replace('/<img ([^ alt="php正则替换有关问题" >]+)src=["\']http[s]?:\/\/www\.aabbcc\.com\/upload\/qrcode_for_gh_2ff16e7c9789_258\.jpg["\'](.*?)>/is', '', $content);
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!