php内容去掉img的方法:1、创建PHP示例文件;2、通过“preg_replace('/]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i','',$str);”删除即可。
本文操作环境:Windows7系统、PHP7.1版、DELL G3电脑
php 怎么实现内容去掉img?
php正则删除img标签的方法。
具体如下:
一、问题
正则抓取过程中需要删除正文中的img标签,如:
<div>欢迎访问<img src="/static/imghwm/default1.png" data-src="https://www.php.cn/images/logo.gif" class="lazy" / alt="How to remove img from content in php" ></div>
要求删除后变成:
<div>欢迎访问</div>
二、解决方法:
$str='<div>欢迎访问<img src="/static/imghwm/default1.png" data-src="https://www.php.cn/images/logo.gif" class="lazy" / alt="How to remove img from content in php" ></div>'; $str= preg_replace('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', '', $str); echo $str;
运行结果:
<div>欢迎访问</div>
推荐学习:《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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Notepad++7.3.1
Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
