Home > Backend Development > PHP Problem > How to delete a tag in php using regular method

How to delete a tag in php using regular method

coldplay.xixi
Release: 2023-03-06 14:16:02
Original
3371 people have browsed it

php正则方法删除a标签的方法:使用函数【preg_replace】保留,代码为【$str = htmlspecialchars_decode($str);$str = preg_replace("/]*>(.*?)<\ a="">/is",】。

How to delete a tag in php using regular method

php正则方法删除a标签的方法:

目的:

使用正则表达式删除下列内容中的a标签,同时保留a标签内容

欢迎来到php中文网www.php.cn
Copy after login
Copy after login

修改后:

欢迎来到php中文网www.php.cn
Copy after login
Copy after login

解决方法:

$str = "
欢迎来到php中文网www.php.cn
";
$str = htmlspecialchars_decode($str);
$str = preg_replace("/]*>(.*?)<\/a>/is", "$1", $str);
echo $str;
运行结果为:
1
Copy after login

想了解更多编程学习,敬请关注php培训栏目!

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