]*>|<\/a>","",$content);" a tag content is enough."> How to delete the content of a tag in php regular code-PHP Problem-php.cn

How to delete the content of a tag in php regular code

藏色散人
Release: 2023-03-08 22:56:02
Original
2040 people have browsed it

php正则删除a标签内容的方法:首先创建一个PHP示例文件;然后通过正则表达式“ereg_replace("]*>|<\ a="">","",$content);”删除a标签内容即可。

How to delete the content of a tag in php regular code

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

PHP使用正则表达式清除超链接文本

可以用$str = preg_replace("/ ]*href=[^>]*>|<\/[^a]*a[^>]*>/i","",$strhtml); 这段来实现需求,如果想要更多解决方法,可以参看以下的。
1、删除内容中的超链接

代码如下:

ereg_replace(']*)>([^<]*)','\\2',$content); ereg_replace("]*>|<\/a>","",$content);
Copy after login

2、消除包含特定词的超链接

代码如下:

3、获取超链接文本内容

代码如下:

//方法一 preg_match_all('/<(a|a)[s]{0,1}[w=":()]*>[nrn]*(check user)[nrn]*/i',$string,$matches); //方法二 preg_match_all('/check user/i',$string,$matches); print_r($matches); //方法三 preg_match_all('/]*>[^<]*/i',$string,$matches); print_r($matches); //方法四 preg_match_all('/check user/is',$str,$arr); print_r($arr); //方法五 preg_match_all('/check user/is',$str,$arr); print_r($arr);
Copy after login

我用了这句 $year = preg_replace("/ ]*href=[^>]*>|<\/[^a]*a[^>]*>/i","",$yearstr);

【推荐学习:PHP视频教程

The above is the detailed content of How to delete the content of a tag in php regular code. 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!