国内流行的内容管理系统(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.

30 lines
653B

  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. $start = 1;
  12. }
  13. else if ($start==1)
  14. {
  15. if ($str[$i]=="<") {
  16. $start = 0;
  17. $alltext .= " ";
  18. }
  19. else if (ord($str[$i])>31)
  20. {
  21. $alltext .= $str[$i];
  22. }
  23. }
  24. }
  25. $alltext = str_replace(" "," ",$alltext);
  26. $alltext = preg_replace("/&([^;&]*)(;|&)/","",$alltext);
  27. $alltext = preg_replace("/[ ]+/s"," ",$alltext);
  28. return $alltext;
  29. }
  30. ?>