国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

php將html轉成wml的WAP標記語言實例

2024-05-04 23:37:30
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了php將html轉成wml的WAP標記語言的方法,實例分析了php實現標簽的轉換與過濾的相關技巧,非常具有實用價值,需要的朋友可以參考下

本文實例講述了php將html轉成wml的WAP標記語言的方法。分享給大家供大家參考。具體實現方法如下:

 

 
  1. <?php 
  2. //--------------------------------------- 
  3. // Html 標記WAP語言 
  4. //---------------------------------------- 
  5. function html2wml($content
  6. //保留圖片 
  7. preg_match_all("/<img([^>]*)>/isU"$content$imgarr); 
  8. if(isset($imgarr[0]) && count($imgarr[0])>0 ) 
  9. foreach($imgarr[0] as $k=>$v$content = str_replace($v"WAP-IMG::{$k}"$content); 
  10. // 過濾掉樣式表和腳本 
  11. $content = preg_replace("/<style .*?<///style>/is"""$content); 
  12. $content = preg_replace("/<script .*?<///script>/is"""$content); 
  13. // 首先將各種可以引起換行的標簽(如<br />、<p> 之類)替換成換行符"//n" 
  14. $content = preg_replace("/<br //s*///?///>/i""//n"$content); 
  15. $content = preg_replace("/<///?p>/i""//n"$content); 
  16. $content = preg_replace("/<///?td>/i""//n"$content); 
  17. $content = preg_replace("/<///?div>/i""//n"$content); 
  18. $content = preg_replace("/<///?blockquote>/i""//n"$content); 
  19. $content = preg_replace("/<///?li>/i""//n"$content); 
  20. // 將""替換為空格 
  21. $content = preg_replace("/////;/i"" "$content); 
  22. $content = preg_replace("////i"" "$content); 
  23. // 過濾掉剩下的 HTML 標簽 
  24. $content = strip_tags($content); 
  25. // 將 HTML 中的實體(entity)轉化為它所對應的字符 
  26. $content = html_entity_decode($content, ENT_QUOTES, "GB2312"); 
  27. // 過濾掉不能轉化的實體(entity) 
  28. $content = preg_replace('///&//#.*?//;/i'''$content); 
  29. // 上面是將 HTML 網頁內容轉化為帶換行的純文本,下面是將這些純文本轉化為 WML。 
  30. $content = str_replace(' 
  31. 希望本文所述對大家的php程序設計有所幫助。 
  32.  
  33. '$'$content); 
  34.  
  35.  
  36. $content = str_replace("//r//n""//n", htmlspecialchars($content)); 
  37. $content = explode("//n"$content); 
  38. for ($i = 0; $i < count($content); $i++) 
  39. $content[$i] = trim($content[$i]); 
  40. // 如果去掉全角空格為空行,則設為空行,否則不對全角空格過濾。 
  41. if (str_replace(' '''$content[$i]) == ''$content[$i] = ''
  42. $content = str_replace("<p><br /></p>//n"""'<p>'.implode("<br /></p>//n<p>"$content)."<br /></p>//n"); 
  43. //還原圖片 
  44. if(isset($imgarr[0]) && count($imgarr[0])>0 ) 
  45. foreach($imgarr[0] as $k=>$v
  46. $attstr = (preg_match('#/$#'$imgarr[1][$k])) ? '<img '.$imgarr[1][$k].'>' : '<img '.$imgarr[1][$k].' />'
  47. $content = str_replace("WAP-IMG::{$k}"$attstr$content); 
  48. $content = preg_replace("/&[a-z]{3,10};/isU"' '$content); 
  49. return $content
  50. function text2wml($content
  51. $content = str_replace(' 
  52. 希望本文所述對大家的php程序設計有所幫助。 
  53.  
  54. '$'$content); 
  55.  
  56.  
  57. $content = str_replace("//r//n""//n", htmlspecialchars($content)); 
  58. $content = explode("//n"$content); 
  59. for ($i = 0; $i < count($content); $i++) 
  60. // 過濾首尾空格 
  61. $content[$i] = trim($content[$i]); 
  62. // 如果去掉全角空格為空行,則設為空行,否則不對全角空格過濾。 
  63. if (str_replace(" """$content[$i]) == ""$content[$i] = ""
  64. //合并各行,轉化為 WML,并過濾掉空行 
  65. $content = str_replace("<p><br /></p>//n""""<p>".implode("<br /></p>//n<p>"$content)."<br /></p>//n"); 
  66. return $content
  67. ?> 

希望本文所述對大家的php程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 洛浦县| 古田县| 句容市| 巢湖市| 合肥市| 抚顺市| 道真| 且末县| 全州县| 临夏县| 达拉特旗| 金寨县| 锦州市| 尼玛县| 民乐县| 卫辉市| 涿州市| 弥渡县| 信丰县| 大埔区| 黔江区| 浙江省| 广灵县| 阜南县| 汤阴县| 如东县| 延吉市| 永寿县| 兰考县| 黑龙江省| 平舆县| 鹰潭市| 潼关县| 安新县| 钦州市| 泰宁县| 巴彦淖尔市| 上高县| 钟祥市| 德保县| 乌兰浩特市|