php 将html 转成wml WAP标记语言
Jun 06, 2016 pm 07:31 PM
html
php
wap
mark
language
php将html转成wmlWAP标记语言 无 源码与演示: 源码出处演示出处 ?php//---------------------------------------// Html 标记WAP语言//----------------------------------------function html2wml($content){ //保留图片 preg_match_all("/img([^]*)/isU",
php 将html 转成wml WAP标记语言
源码与演示:源码出处 演示出处
<?php //--------------------------------------- // Html 标记WAP语言 //---------------------------------------- function html2wml($content) { //保留图片 preg_match_all("/<img ([^ alt="php 将html 转成wml WAP标记语言" >]*)>/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].' alt="php 将html 转成wml WAP标记语言" >' : '<img '.$imgarr[1][$k].' / alt="php 将html 转成wml WAP标记语言" >'; $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; } ?>
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian
