这篇文章主要为大家详细介绍了使用php怎么将html转换成wml,文中示例代码介绍的非常详细,具有一定的参考价值,发现的小伙伴们可以参考一下:
html有什么特点
1,简易性:超级文本标记语言版本升级采用超集方式,从而更加灵活方便,适合初学前端开发者使用。 2、可扩展性:超级文本标记语言的广泛应用带来了加强功能,增加标识符等要求,超级文本标记语言采取子类元素的方式,为系统扩展带来保证只 3、平台无关性:超级文本标记语言能够在广泛的平台上使用,这也是万维网盛行的一个原因。 4、通用性:HTML是网络的通用语言,它允许网页制作人建立文本与图片相结合的复杂页面,这些页面可以被网上任何其他人浏览到,无论使用的是什么类型的电脑或浏览器。
具体实现方法如下:
& lt; php ?//---------------------------------------//,Html 标记WAP语言//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - function html2wml(内容) {//保才能留图片 preg_match_all才能(“/& lt; img([^的在]*)祝辞/isU",,内容,美元,美元imgarr); 如果才能(收取($ imgarr[0]),,,,计数($ imgarr[0])在0,) {才能 ,,foreach ($ imgarr [0], as $ k=祝辞v)美元,美元content =, str_replace (v,美元,“WAP-IMG:: {$ k},,,美元内容); ,,}//,才能过滤掉样式表和脚本=美元才能content preg_replace (“/& lt; style 。* ? & lt; \ \/style>/女儿家,,,,,,,美元内容);=美元才能content preg_replace (“/& lt; script 。* ? & lt; \ \/script>/女儿家,,,,,,,美元内容);//才能,首先将各种可以引起换行的标签(如& lt; br /祝辞,& lt; p>,之类)替换成换行符“\ \ n" 时间=美元才能content preg_replace (“/& lt; br \ \ * \ \/? \ \/在/我,,“\ \ n",,美元内容); 时间=美元才能content preg_replace (“/& lt; \ \/? p>/我,,“\ \ n",,美元内容); 时间=美元才能content preg_replace (“/& lt; \ \/? td>/我,,“\ \ n",,美元内容); 时间=美元才能content preg_replace (“/& lt; \ \/? div>/我,,“\ \ n",,美元内容); 时间=美元才能content preg_replace (“/& lt; \ \/? blockquote>/我,,“\ \ n",,美元内容); 时间=美元才能content preg_replace (“/& lt; \ \/? li>/我,,“\ \ n",,美元内容);//,才能将“和,“替换为空格 时间=美元才能content preg_replace(“/\ \,盼\ \;/我,,,,,,,美元内容); 时间=美元才能content preg_replace(“/\ \,/我盼,,,,,,,美元内容);//,才能过滤掉剩下的,HTML 标签 时间=美元才能content strip_tags($内容);//,才能将,HTML 中的实体(实体)转化为它所对应的字符=美元才能content 编码(内容、美元,ENT_QUOTES,,“GB2312");//,才能过滤掉不能转化的实体(实体)=美元才能content preg_replace(& # 39;/\ \, \ \ #。* ? \ \;/我# 39;,,& # 39;& # 39;,,美元内容);//,才能上面是将,HTML 网页内容转化为带换行的纯文本,下面是将这些纯文本转化为,WML。 时间=美元才能content str_replace(& # 39; $ & # 39;, & # 39; $ $ & # 39;,,美元内容); 时间=美元才能content str_replace (“\ \ r \ \ n",,“\ \ n",, htmlspecialchars函数(内容)美元); 时间=美元才能content 爆炸(“\ \ n",,美元内容); for 才能;($小姐:=,0;,美元小姐:& lt;, count($内容);,我+ +)美元 {才能 美元才能内容[$ i],=,修剪($内容($ i));//才能,如果去掉全角空格为空行,则设为空行,否则不对全角空格过滤。 if 才能;((& # 39;大小写不敏感& # 39;,& # 39;& # 39;,,内容[$ i]),美元==,& # 39;& # 39;),内容[我]美元美元,=,& # 39;& # 39;; ,,}=美元才能content str_replace (“& lt; p> & lt; br /祝辞& lt;/p> \ \ n",,,,,, & # 39; & lt; p> & # 39; .implode (“& lt; br /祝辞& lt;/p> \ \ n“,,内容)美元霸主地位;& lt; br /祝辞& lt;/p> \ \ n");//才能还原图片 如果才能(收取($ imgarr[0]),,,,计数($ imgarr[0])在0,) {才能 ,,,foreach()美元imgarr [0], as $ k=祝辞v)美元 ,,,{ ,,,,attstr 美元;=,(preg_match(& # 39; #/$ # & # 39;,,美元imgarr [1] [$ k])), ?, & # 39; & lt; img & # 39; imgarr美元。[1][$ k]强生# 39;祝辞& # 39;,:,& # 39;& lt; img & # 39; imgarr美元。[1][$ k] # 39;公司,/祝辞;& # 39;; ,,,,content 美元;=,str_replace (“WAP-IMG: {$ k},,, attstr美元,美元的内容); ,,,} ,,} content 美元;才能=,preg_replace (“/, amp; [a - z] {3, 10},/isU",, & # 39;, & # 39;,,美元内容); 美元return 才能;内容; } function text2wml(内容) { 时间=美元才能content str_replace(& # 39; $ & # 39;, & # 39; $ $ & # 39;,,美元内容); 时间=美元才能content str_replace (“\ \ r \ \ n",,“\ \ n",, htmlspecialchars函数(内容)美元); 时间=美元才能content 爆炸(“\ \ n",,美元内容); for 才能;($小姐:=,0;,美元小姐:& lt;, count($内容);,我+ +)美元 {才能//,才能过滤首尾空格 null null null null null null null null null
使用php怎么将html转换成wml