php过滤html标签

正常情况下:

<?php
$a='<p><span style="color:red;">我的外面包裹着html标签<br/>我的上面的换行标签</span></p>';
echo $a;
?>

在这里插入图片描述

使用了strip_tags标签后

<?php
$a='<p><span style="color:red;">我的外面包裹着html标签<br/>我的上面的换行标签</span></p>';
echo strip_tags($a);
?>

在这里插入图片描述

过滤某个html标签

该正则表达式为万能公式

<?php
$a='<p><span style="color:red;">我的外面包裹着html标签<br/>我的上面的换行标签</span></p>';
$str=preg_replace("/<(\/?span.*?)>/si","",$a);
echo $str;
?>

在这里插入图片描述
查看源码:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_42249896/article/details/85074309