PHP regular method to delete img tag

怪我咯
Release: 2023-03-12 18:42:01
Original
2312 people have browsed it

这篇文章主要介绍了php正则删除img标签的方法,结合具体实例形式分析了php针对img标签正则匹配相关操作技巧,需要的朋友可以参考下

本文实例讲述了php正则删除img标签的方法。分享给大家供大家参考,具体如下:

一、问题

正则抓取过程中需要删除正文中的img标签,如:

<p>欢迎访问PHP中文网<img src="http://www.www.vn/images/logo.gif" /></p>
Copy after login

要求删除后变成:

<p>欢迎访问PHP中文网</p>
Copy after login

二、解决方法:

$str='<p>欢迎访问PHP中文网<img src="http://www.www.vn/images/logo.gif" /></p>';
$str= preg_replace('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', '', $str);
echo $str;
Copy after login

运行结果:

<p>欢迎访问PHP中文网</p>
Copy after login

The above is the detailed content of PHP regular method to delete img tag. For more information, please follow other related articles on the PHP Chinese website!

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!