]*?src\s*=\s*(\'|\" )(.*?)\\1[^>]...>;" method to remove the picture."> How to remove images from content using php regular expressions-PHP Problem-php.cn

How to remove images from content using php regular expressions

藏色散人
Release: 2023-03-11 13:30:02
Original
1891 people have browsed it

php正则去掉内容中图片的方法:首先创建一个PHP示例文件;然后通过“preg_replace('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]...>;”方法去掉图片即可。

How to remove images from content using php regular expressions

本文操作环境:Windows7系统、PHP7.1版,DELL G3电脑

php 正则怎么去掉内容中的图片?

php正则删除img标签的方法。

具体如下:

一、问题

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

欢迎访问php中文网
Copy after login

要求删除后变成:

欢迎访问php中文网
Copy after login
Copy after login

二、解决方法:

$str='
欢迎访问php中文网
'; $str= preg_replace('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', '', $str); echo $str;
Copy after login

运行结果:

欢迎访问php中文网
Copy after login
Copy after login

推荐学习:《PHP视频教程

The above is the detailed content of How to remove images from content using php regular expressions. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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
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!