详细内容可以参考 周小蛇的秘密花园 ---- PHP手写方法之 过滤HTML字符 http://zhousir.net/php-html-filtering-method-handwritten-characters.html
- function html2text($str){
- $str = trim($str);
- $str = preg_replace("/||/isU","",$str);
- $alltext = "";
- $start = 1;
- for($i=0;$i31){
- $alltext .= $str[$i];
- }
- }
- }
- $alltext = str_replace(" "," ",$alltext);
- $alltext = preg_replace("/&([^;&]*)(;|&)/","",$alltext);
- $alltext = preg_replace("/[ ]+/s"," ",$alltext);
- $alltext = htmlspecialchars($alltext,ENT_QUOTES);
- return $alltext;
- }
复制代码
|