国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
655B

  1. <?php
  2. if (!defined('DEDEINC')) exit('dedebiz');
  3. function SpHtml2Text($str)
  4. {
  5. $str = preg_replace("/<sty(.*)\\/style>|<scr(.*)\\/script>|<!--(.*)-->/isU","",$str);
  6. $alltext = "";
  7. $start = 1;
  8. for($i=0;$i<strlen($str);$i++)
  9. {
  10. if($start==0 && $str[$i]==">")
  11. {
  12. $start = 1;
  13. }
  14. else if($start==1)
  15. {
  16. if($str[$i]=="<")
  17. {
  18. $start = 0;
  19. $alltext .= " ";
  20. }
  21. else if(ord($str[$i])>31)
  22. {
  23. $alltext .= $str[$i];
  24. }
  25. }
  26. }
  27. $alltext = str_replace(" "," ",$alltext);
  28. $alltext = preg_replace("/&([^;&]*)(;|&)/","",$alltext);
  29. $alltext = preg_replace("/[ ]+/s"," ",$alltext);
  30. return $alltext;
  31. }
  32. ?>