//1,如何去掉出现“微信号”及紧邻的标签对,如下代码中去掉这块内容:<div>这里有很多其他字符、表单等等....微信号...这里有很多其他字符、表单等等</div> $content = "0000<div>111<div>222<div>这里有很多其他字符、表单等等....微信号...这里有很多其他字符、表单等等</div>222</div>111</div>0000"; //2,如何去掉出现qrcode_for_gh_2ff16e7c9789_258.jpg的图片 $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">'; // $content = preg_replace('/<img (.*?)src=["\']http[s]?:\/\/www\.aabbcc\.com\/upload\/qrcode_for_gh_2ff16e7c9789_258\.jpg["\'](.*?) alt="php正则替换问题" >/is', '', $content); var_dump( $content );
1、echo preg_replace('/<[^>]+>[^<>]*微信号[^<>]*<[^>]+>/u', '', $content);2、$content = preg_replace('/<img ([^ alt="php正则替换问题" >]+)src=["\']http[s]?:\/\/www\.aabbcc\.com\/upload\/qrcode_for_gh_2ff16e7c9789_258\.jpg["\'](.*?)>/is', '', $content); 版主
1、echo preg_replace('/<[^>]+>[^<>]*微信号[^<>]*<[^>]+>/u', '', $content);2、$content = preg_replace('/<img ([^ alt="php正则替换问题" >]+)src=["\']http[s]?:\/\/www\.aabbcc\.com\/upload\/qrcode_for_gh_2ff16e7c9789_258\.jpg["\'](.*?)>/is', '', $content);哪个为空了?
哪个为空了?
$content = "0000<div>111<div>222<div>这里有很多其他字符、表单等等....微信号...这里有很多其他字符、表单等等</div>222</div>111</div>0000"; $content = preg_replace('/<[^>]+>[^<>]*微信号[^<>]*<[^>]+>/', '', $content);// 去掉修饰符就可以了
哪个为空了?
<div><span style="word-wrap: break-word; font-weight: 700; color: rgb(68, 68, 68); font-family: Tahoma, 'Microsoft Yahei', Simsun; line-height: 21px;"> <font style="word-wrap: break-word; background-color: yellow;">扫描二维码</font> 或直接搜索微信号:<font style="word-wrap: break-word; background-color: yellow;"> mcq28tui</font> </span></div>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号