代码如下
//清除html function clearhtml($str){ $str = trim($str); $str = strip_tags($str,""); $str=strip_tags($str,"");//利用php自带的函数清除html格式 $str=preg_replace("/\t/","",$str);//使用正则表达式匹配需要替换的内容,如空格和换行,并将替换为空 $str=preg_replace("/\r\n/","",$str); $str=preg_replace("/\r/","",$str); $str=preg_replace("/\n/","",$str); $str=preg_replace("/ /","",$str);//匹配html中的空格 $str=preg_replace("/ /","",$str);//匹配html中的空格 return trim($str); }
本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/3557895.html,如需转载请自行联系原作者