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

首頁 > 網站 > 建站經驗 > 正文

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

2024-04-25 20:38:37
字體:
來源:轉載
供稿:網友

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

<?php

//---------------------------------------

// Html 標記WAP語言

//----------------------------------------

function html2wml($content)

{

//保留圖片

preg_match_all("/<img([^>]*)>/isU", $content, $imgarr);

if(isset($imgarr[0]) && count($imgarr[0])>0 )

{

foreach($imgarr[0] as $k=>$v) $content = str_replace($v, "WAP-IMG::{$k}", $content);

}

// 過濾掉樣式表和腳本

$content = preg_replace("/<style .*?<///style>/is", "", $content);

$content = preg_replace("/<script .*?<///script>/is", "", $content);

// 首先將各種可以引起換行的標簽(如<br />、<p> 之類)替換成換行符"//n"

$content = preg_replace("/<br //s*///?///>/i", "//n", $content);

$content = preg_replace("/<///?p>/i", "//n", $content);

$content = preg_replace("/<///?td>/i", "//n", $content);

$content = preg_replace("/<///?div>/i", "//n", $content);

$content = preg_replace("/<///?blockquote>/i", "//n", $content);

$content = preg_replace("/<///?li>/i", "//n", $content);

// 將" "替換為空格

$content = preg_replace("/// //;/i", " ", $content);

$content = preg_replace("/// /i", " ", $content);

// 過濾掉剩下的 HTML 標簽

$content = strip_tags($content);

// 將 HTML 中的實體(entity)轉化為它所對應的字符

$content = html_entity_decode($content, ENT_QUOTES, "GB2312");

// 過濾掉不能轉化的實體(entity)

$content = preg_replace('///&//#.*?//;/i', '', $content);

// 上面是將 HTML 網頁內容轉化為帶換行的純文本,下面是將這些純文本轉化為 WML。

$content = str_replace('$', '$$', $content);

$content = str_replace("//r//n", "//n", htmlspecialchars($content));

$content = explode("//n", $content);

for ($i = 0; $i < count($content); $i++)

{

$content[$i] = trim($content[$i]);

// 如果去掉全角空格為空行,則設為空行,否則不對全角空格過濾。

if (str_replace(' ', '', $content[$i]) == '') $content[$i] = '';

}

$content = str_replace("<p><br /></p>//n", "", '<p>'.implode("<br /></p>//n<p>", $content)."<br /></p>//n");

//還原圖片

if(isset($imgarr[0]) && count($imgarr[0])>0 )

{

foreach($imgarr[0] as $k=>$v)

{

$attstr = (preg_match('#/$#', $imgarr[1][$k])) ? '<img '.$imgarr[1][$k].'>' : '<img '.$imgarr[1][$k].' />';

$content = str_replace("WAP-IMG::{$k}", $attstr, $content);

}

}

$content = preg_replace("/&[a-z]{3,10};/isU", ' ', $content);

return $content;

}

function text2wml($content)

{

$content = str_replace('$', '$$', $content);

$content = str_replace("//r//n", "//n", htmlspecialchars($content));

$content = explode("//n", $content);

for ($i = 0; $i < count($content); $i++)

{

// 過濾首尾空格

$content[$i] = trim($content[$i]);

// 如果去掉全角空格為空行,則設為空行,否則不對全角空格過濾。

if (str_replace(" ", "", $content[$i]) == "") $content[$i] = "";

}

//合并各行,轉化為 WML,并過濾掉空行

$content = str_replace("<p><br /></p>//n", "", "<p>".implode("<br /></p>//n<p>", $content)."<br /></p>//n");

return $content;

}

?>

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 平山县| 广德县| 宜兴市| 曲麻莱县| 凤凰县| 永修县| 锦州市| 工布江达县| 开封县| 西畴县| 香港| 抚松县| 澄迈县| 准格尔旗| 兴文县| 浦北县| 武汉市| 井冈山市| 东乌珠穆沁旗| 吉林省| 尼玛县| 连江县| 娄烦县| 西乌| 苍梧县| 旬阳县| 嘉荫县| 古丈县| 根河市| 淮南市| 武平县| 滨州市| 岳池县| 安庆市| 西盟| 通海县| 通化市| 牡丹江市| 新疆| 怀宁县| 广宁县|