目的:
使用正则表达式删除下列内容中的a标签,同时保留a标签内容
<div>欢迎来到php中文网<a href=//www.php.cn>www.php.cn</a></div>
修改后:
<div>欢迎来到php中文网www.php.cn</div>
解决方法:
$str = "<div>欢迎来到php中文网<a href=//www.php.cn>www.php.cn</a></div>"; $str = htmlspecialchars_decode($str); $str = preg_replace("/]*>(.*?)<\/a>/is", "$1", $str); echo $str;
运行结果为:
立即学习“PHP免费学习笔记(深入)”;
<div>欢迎来到php中文网www.php.cn</div>
更多相关教程请访问php中文网。
以上就是php中如何使用正则表达式删除a标签的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号