php下清空字符串中的HTML标签的代码

前端之家收集整理的这篇文章主要介绍了php下清空字符串中的HTML标签的代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

本文介绍了PHP 清空字符串中的html标签
要过滤字符串中所有的html标签有两种方法一种是我们自己写一个函数,用正则过滤,一个是用PHP自带函数strip_tags哦。 <div class="codetitle"><a style="CURSOR: pointer" data="90134" class="copybut" id="copybut90134" onclick="doCopy('code90134')"> 代码如下:

<div class="codebody" id="code90134">
function clear_html_label($html)
{
$search = array ("'<script[^>]?>.?'si","'<[/!]?[^<>]?>'si","'([rn])[s]+'","'&(quot|#34);'i","'&(amp|#38);'i","'&(lt|#60);'i","'&(gt|#62);'i","'&(nbsp|#160);'i","'&(iexcl|#161);'i","'&(cent|#162);'i","'&(pound|#163);'i","'&(copy|#169);'i","'&#(d+);'e");
$replace = array ("","","1",""","&","<",">"," ",chr(161),chr(162),chr(163),chr(169),"chr(1)"); return preg_replace($search,$replace,$html);
} //实例应用 $string ='aaa

猜你在找的PHP相关文章