]*?src\s*=\s*(\'|\") (.*?)\\1[^>]*?\/?\s*>/i','',$str);" Just delete it."/> ]*?src\s*=\s*(\'|\") (.*?)\\1[^>]*?\/?\s*>/i','',$str);" Just delete it.">

Home  >  Article  >  Backend Development  >  How to remove img from content in php

How to remove img from content in php

藏色散人
藏色散人Original
2022-01-24 10:11:312229browse

php内容去掉img的方法:1、创建PHP示例文件;2、通过“preg_replace('/911a089107768724fb33c87b2462853f]*?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标签,如:

欢迎访问

要求删除后变成:

欢迎访问

二、解决方法:

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

运行结果:

欢迎访问

推荐学习:《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!

Statement:
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