前端之家收集整理的这篇文章主要介绍了
php过滤html字符串函数的简单示例,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
对
PHP过滤html字符串
函数感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编两巴掌来看看吧!
/**
* PHP过滤html字符串函数
*
* @param
* @arrange 512-笔记网: jb51.cc
**/
function StripHTML($string){
$pattern=array ("'<script[^>]*?>.*?</script>'si","'<style[^>]*?>.*?</style>'si","'<[\/\!]*?[^<>]*?>'si","'([\r\n])[\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 ($pattern,$replace,$str);
}
/*** 来自编程之家 jb51.cc(jb51.cc) ***/
原文链接:https://www.f2er.com/php/528032.html