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