Home >Backend Development >PHP Tutorial >Filter content with html tags

Filter content with html tags

WBOY
WBOYOriginal
2016-07-25 09:09:451025browse

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

  1. function html2text($str){
  2. $str = trim($str);
  3. $str = preg_replace("/||/isU","" ,$str);
  4. $alltext = "";
  5. $start = 1;
  6. for($i=0;$i31){
  7. $alltext .= $str[$i];
  8. }
  9. }
  10. }
  11. $ alltext = str_replace(" "," ",$alltext);
  12. $alltext = preg_replace("/&([^;&]*)(;|&)/","",$alltext);
  13. $alltext = preg_replace("/[ ]+/s"," ",$alltext);
  14. $alltext = htmlspecialchars($alltext,ENT_QUOTES);
  15. return $alltext;
  16. }
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn