国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

112 řádky
4.3KB

  1. <?php
  2. if(!defined('DEDEINC')) exit('Request Error!');
  3. require_once(DEDEINC.'/channelunit.class.php');
  4. //---------------------------------------
  5. // Html 标记WAP语言
  6. //----------------------------------------
  7. function html2wml($content)
  8. {
  9. //保留图片
  10. preg_match_all("/<img([^>]*)>/isU", $content, $imgarr);
  11. if(isset($imgarr[0]) && count($imgarr[0])>0 )
  12. {
  13. foreach($imgarr[0] as $k=>$v) $content = str_replace($v, "WAP-IMG::{$k}", $content);
  14. }
  15. // 过滤掉样式表和脚本
  16. $content = preg_replace("/<style .*?<\/style>/is", "", $content);
  17. $content = preg_replace("/<script .*?<\/script>/is", "", $content);
  18. // 首先将各种可以引起换行的标签(如<br />、<p> 之类)替换成换行符"\n"
  19. $content = preg_replace("/<br \s*\/?\/>/i", "\n", $content);
  20. $content = preg_replace("/<\/?p>/i", "\n", $content);
  21. $content = preg_replace("/<\/?td>/i", "\n", $content);
  22. $content = preg_replace("/<\/?div>/i", "\n", $content);
  23. $content = preg_replace("/<\/?blockquote>/i", "\n", $content);
  24. $content = preg_replace("/<\/?li>/i", "\n", $content);
  25. // 将"&nbsp;"替换为空格
  26. $content = preg_replace("/\&nbsp\;/i", " ", $content);
  27. $content = preg_replace("/\&nbsp/i", " ", $content);
  28. // 过滤掉剩下的 HTML 标签
  29. $content = strip_tags($content);
  30. // 将 HTML 中的实体(entity)转化为它所对应的字符
  31. $content = html_entity_decode($content, ENT_QUOTES, "GB2312");
  32. // 过滤掉不能转化的实体(entity)
  33. $content = preg_replace('/\&\#.*?\;/i', '', $content);
  34. // 上面是将 HTML 网页内容转化为带换行的纯文本,下面是将这些纯文本转化为 WML。
  35. $content = str_replace('$', '$$', $content);
  36. $content = str_replace("\r\n", "\n", dede_htmlspecialchars($content));
  37. $content = explode("\n", $content);
  38. for ($i = 0; $i < count($content); $i++)
  39. {
  40. $content[$i] = trim($content[$i]);
  41. // 如果去掉全角空格为空行,则设为空行,否则不对全角空格过滤。
  42. if (str_replace(' ', '', $content[$i]) == '') $content[$i] = '';
  43. }
  44. $content = str_replace("<p><br /></p>\n", "", '<p>'.implode("<br /></p>\n<p>", $content)."<br /></p>\n");
  45. //还原图片
  46. if(isset($imgarr[0]) && count($imgarr[0])>0 )
  47. {
  48. foreach($imgarr[0] as $k=>$v)
  49. {
  50. $attstr = (preg_match('#/$#', $imgarr[1][$k])) ? '<img '.$imgarr[1][$k].'>' : '<img '.$imgarr[1][$k].' />';
  51. $content = str_replace("WAP-IMG::{$k}", $attstr, $content);
  52. }
  53. }
  54. $content = preg_replace("/&amp;[a-z]{3,10};/isU", ' ', $content);
  55. return $content;
  56. }
  57. function text2wml($content)
  58. {
  59. $content = str_replace('$', '$$', $content);
  60. $content = str_replace("\r\n", "\n", dede_htmlspecialchars($content));
  61. $content = explode("\n", $content);
  62. for ($i = 0; $i < count($content); $i++)
  63. {
  64. // 过滤首尾空格
  65. $content[$i] = trim($content[$i]);
  66. // 如果去掉全角空格为空行,则设为空行,否则不对全角空格过滤。
  67. if (str_replace(" ", "", $content[$i]) == "") $content[$i] = "";
  68. }
  69. //合并各行,转化为 WML,并过滤掉空行
  70. $content = str_replace("<p><br /></p>\n", "", "<p>".implode("<br /></p>\n<p>", $content)."<br /></p>\n");
  71. return $content;
  72. }
  73. //----------------------
  74. //把GBK字符转换成UTF8
  75. //----------------------
  76. function ConvertCharset($varlist)
  77. {
  78. global $cfg_soft_lang;
  79. if(preg_match('#utf#i',$cfg_soft_lang)) return 0;
  80. $varlists = explode(',',$varlist);
  81. $numargs=count($varlists);
  82. for($i = 0; $i < $numargs; $i++)
  83. {
  84. if(isset($GLOBALS[$varlists[$i]]))
  85. {
  86. $GLOBALS[$varlists[$i]] = gb2utf8($GLOBALS[$varlists[$i]]);
  87. }
  88. }
  89. return 1;
  90. }
  91. //----------------------
  92. //处理特殊字符
  93. //----------------------
  94. function ConvertStr($str)
  95. {
  96. $str = str_replace("&amp;","##amp;",$str);
  97. $str = str_replace("&","&amp;",$str);
  98. $str = preg_replace("#[\"><']#","",$str);
  99. $str = str_replace("##amp;","&amp;",$str);
  100. return $str;
  101. }
  102. ?>