目的:
使用正则表达式删除下列内容中的a标签,同时保留a标签内容
<div>欢迎来到php中文网<a href=//m.sbmmt.com>m.sbmmt.com</a></div>
修改后:
<div>欢迎来到php中文网m.sbmmt.com</div>
解决方法:
$str = "<div>欢迎来到php中文网<a href=//m.sbmmt.com>m.sbmmt.com</a></div>"; $str = htmlspecialchars_decode($str); $str = preg_replace("/<a[^>]*>(.*?)<\/a>/is", "$1", $str); echo $str;
运行结果为:
<div>欢迎来到php中文网m.sbmmt.com</div>
更多相关教程请访问php中文网。
以上就是php中如何使用正则表达式删除a标签的详细内容,更多请关注php中文网其它相关文章!
已抢186663个
抢已抢67309个
抢已抢353098个
抢已抢667338个
抢已抢122468个
抢已抢24016个
抢