php中如何使用正则表达式删除a标签-PHP问题

资源魔 14 0

目的:

应用正则表白式删除了下列内容中的a标签,同时保存a标签内容

<div>欢送来到资源魔<a href=//www.php.cn>www.php.cn</a></div>

修正后:

<div>欢送来到资源魔www.php.cn</div>

处理办法:

$str = "<div>欢送来到资源魔<a href=//www.php.cn>www.php.cn</a></div>";
$str = htmlspecialchars_decode($str);
$str = preg_replace("/<a[^>]*>(.*?)<\/a>/is", "$1", $str);
echo $str;

运转后果为:

<div>欢送来到资源魔www.php.cn</div>

更多相干教程请拜访资源魔。

以上就是php中若何应用正则表白式删除了a标签的具体内容,更多请存眷资源魔其它相干文章!

标签: php php教程 正则表达式 php故障解决 php使用问题 a标签

抱歉,评论功能暂时关闭!