欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php下清空字符串中的HTML標(biāo)簽的代碼

 更新時間:2010年09月06日 21:03:56   作者:  
要過濾字符串中所有的html標(biāo)簽有兩種方法一種是我們自己寫一個函數(shù),用正則過濾,一個是用php自帶函數(shù)strip_tags哦。
本文介紹了php 清空字符串中的html標(biāo)簽
要過濾字符串中所有的html標(biāo)簽有兩種方法一種是我們自己寫一個函數(shù),用正則過濾,一個是用php自帶函數(shù)strip_tags哦。

復(fù)制代碼 代碼如下:

function clear_html_label($html)
{
$search = array ("'<script[^>]*?>.*?</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);
}

//實例應(yīng)用

$string ='aaa<br /> <script>fdsafsa';
echo clear_html_label($string);//aaa fdsafsa

//利用php自帶函數(shù)strip_tags(); www.zzarea.com
echo strip_tags($string);//aaa fdsafsa


總結(jié),
上面二個函數(shù)得出的結(jié)果完全相同,一個是用戶自定義的過濾所有html函數(shù),一個是php內(nèi)置函數(shù),但在效綠上來說php的strip_tags()函數(shù),肯定要高很多。至少為什么我就不說多了。

相關(guān)文章

最新評論