php将html转成wml的WAP标记语言实例
本文实例讲述了php将html转成wml的WAP标记语言的方法。分享给大家供大家参考。具体实现方法如下:
<&#63;php //--------------------------------------- // Html 标记WAP语言 //---------------------------------------- function html2wml($content) { //保留图片 preg_match_all("/]*)>/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("//is", "", $content); $cOntent= preg_replace("//is", "", $content); // 首先将各种可以引起换行的标签(如
、之类)替换成换行符"\\n" $cOntent= preg_replace("/
\\n", "", '
/i", "\\n", $content); $cOntent= preg_replace("/<\\/&#63;p>/i", "\\n", $content); $cOntent= preg_replace("/<\\/&#63;td>/i", "\\n", $content); $cOntent= preg_replace("/<\\/&#63;div>/i", "\\n", $content); $cOntent= preg_replace("/<\\/&#63;blockquote>/i", "\\n", $content); $cOntent= preg_replace("/<\\/&#63;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('/\\&\\#.*&#63;\\;/i', '', $content); // 上面是将 HTML 网页内容转化为带换行的纯文本,下面是将这些纯文本转化为 WML。 $cOntent= str_replace('$', '$$', $content); $cOntent= str_replace("\\r\\n", "\\n", htmlspecialchars($content)); $cOntent= explode("\\n", $content); for ($i = 0; $i'.implode("
\\n", $content)."
\\n"); //还原图片 if(isset($imgarr[0]) && count($imgarr[0])>0 ) { foreach($imgarr[0] as $k=>$v) { $attstr = (preg_match('#/$#', $imgarr[1][$k])) &#63; '' : ''; $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
\\n", "", "".implode("
\\n", $content)."
\\n"); return $content; } &#63;>
希望本文所述对大家的php程序设计有所帮助。
内容推荐:免费高清PNG素材下载
PHP之友评论