For details, please refer to Zhou Xiaoshe’s Secret Garden---- PHP Handwriting Method for Filtering HTML Characters 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;
- }
Copy code
|