How to remove img from content in php

藏色散人
Release: 2023-03-14 22:38:01
Original
2348 people have browsed it

php内容去掉img的方法:1、创建PHP示例文件;2、通过“preg_replace('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i','',$str);”删除即可。

How to remove img from content in php

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

php 怎么实现内容去掉img?

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

具体如下:

一、问题

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

<div>欢迎访问<img src="https://www.php.cn/images/logo.gif" /></div>
Copy after login

要求删除后变成:

<div>欢迎访问</div>
Copy after login
Copy after login

二、解决方法:

$str='<div>欢迎访问<img src="https://www.php.cn/images/logo.gif" /></div>';
$str= preg_replace('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', '', $str);
echo $str;
Copy after login

运行结果:

<div>欢迎访问</div>
Copy after login
Copy after login

推荐学习:《PHP视频教程

The above is the detailed content of How to remove img from content in php. 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