HTML转换成UBB代码的JAVASCRIPT和ASP函数程序
作者:随然 日期:2009-04-05
在做网站的过程中,经常会遇到把UBB代码的文字内容转换成HTML代码显示出来,有的时候也会把HTML代码转换成UBB代码。比如在使用ASP+WML制作WAP网站的过程中,就遇到了这个问题。
文字内容包含有<table><tr><td>等HTML的代码,手机浏览时无法正常在WML页面中显示出来,所以就可以把这些HTML代码标签转换成UBB代码,然后再转换成简单的WML支持的HTML代码显示出来。
下面提供两种代码供大家选择:
第一种:JAVASCRIPT代码
HTML代码
1、选择HTML内容,比如有链接,或者颜色的拷贝。
2、点击运行代码按钮
3、直接点击转换
4、出来的就是论坛专用的 ubb 代码了。
第二种:ASP代码
复制内容到剪贴板 程序代码
<%
function html2ubb(l1)
if len(trim(l1))>0 then
else
exit function
end if
dim l4,I1,I2,I3
dim i,I4:I4=array(16,19,21,24,32,45)
I1=l1
set I2=new regexp
I2.global=true
I2.ignorecase=true'忽略大小写
I2.pattern="/r":I1=I2.replace(I1,"")
I2.pattern="on(load|click|dbclick|mouseover|mousedown|mouseup)=""[^""]+""":I1=I2.replace(I1,"")
I2.pattern="<script[^>]*?>([\w\W]*?)<\/script>":I1=I2.replace(I1,"")
I2.pattern="<a[^>]+href=""([^""]+)""[^>]*>(.*?)<\/a>":I1=I2.replace(I1,"$2")
I2.pattern="<font[^>]+color=([^ >]+)[^>]*>(.*?)<\/font>":I1=I2.replace(I1,"[color=$1]$2[/color]")
I2.pattern="<img[^>]+src=""([^""]+)""[^>]*>":I1=I2.replace(I1,"")
I2.pattern="<([\/]?)b>":I1=I2.replace(I1,"[$1b]")
I2.pattern="<([\/]?)strong>":I1=I2.replace(I1,"[$1b]")
I2.pattern="<([\/]?)u>":I1=I2.replace(I1,"[$1u]")
I2.pattern="<([\/]?)i>":I1=I2.replace(I1,"[$1i]")
I2.pattern=" ":I1=I2.replace(I1," ")
I2.pattern="&":I1=I2.replace(I1,"&")
I2.pattern="""":I1=I2.replace(I1,"""")
I2.pattern="<":I1=I2.replace(I1,"<")
I2.pattern=">":I1=I2.replace(I1,">")
I2.pattern="<br />":I1=I2.replace(I1,vbcrlf)
I2.pattern="<[^>]*?>":I1=I2.replace(I1,"")
I2.pattern="\n+":I1=I2.replace(I1,vbcrlf)
set I2=nothing
html2ubb=I1
end function
%>
function html2ubb(l1)
if len(trim(l1))>0 then
else
exit function
end if
dim l4,I1,I2,I3
dim i,I4:I4=array(16,19,21,24,32,45)
I1=l1
set I2=new regexp
I2.global=true
I2.ignorecase=true'忽略大小写
I2.pattern="/r":I1=I2.replace(I1,"")
I2.pattern="on(load|click|dbclick|mouseover|mousedown|mouseup)=""[^""]+""":I1=I2.replace(I1,"")
I2.pattern="<script[^>]*?>([\w\W]*?)<\/script>":I1=I2.replace(I1,"")
I2.pattern="<a[^>]+href=""([^""]+)""[^>]*>(.*?)<\/a>":I1=I2.replace(I1,"$2")
I2.pattern="<font[^>]+color=([^ >]+)[^>]*>(.*?)<\/font>":I1=I2.replace(I1,"[color=$1]$2[/color]")
I2.pattern="<img[^>]+src=""([^""]+)""[^>]*>":I1=I2.replace(I1,"")
I2.pattern="<([\/]?)b>":I1=I2.replace(I1,"[$1b]")
I2.pattern="<([\/]?)strong>":I1=I2.replace(I1,"[$1b]")
I2.pattern="<([\/]?)u>":I1=I2.replace(I1,"[$1u]")
I2.pattern="<([\/]?)i>":I1=I2.replace(I1,"[$1i]")
I2.pattern=" ":I1=I2.replace(I1," ")
I2.pattern="&":I1=I2.replace(I1,"&")
I2.pattern="""":I1=I2.replace(I1,"""")
I2.pattern="<":I1=I2.replace(I1,"<")
I2.pattern=">":I1=I2.replace(I1,">")
I2.pattern="<br />":I1=I2.replace(I1,vbcrlf)
I2.pattern="<[^>]*?>":I1=I2.replace(I1,"")
I2.pattern="\n+":I1=I2.replace(I1,vbcrlf)
set I2=nothing
html2ubb=I1
end function
%>
使用方法:
htmlcontent="含有HTML代码的内容"
Response.Write html2ubb(htmlcontent)
点击下载上面两个代码文件
提供几个网页供大家参考:
http://tool.alimama.com/htmltoubb.php
http://www.7747.net/online/gj/htmtoubb.htm
http://www.blueidea.com/tech/web/2003/1486.asp
http://blog.csdn.net/MPU/archive/2009/02/23/3929212.aspx
[本日志由 随然 于 2009-04-05 09:04 PM 编辑]
上一篇: 让IIS支持调试WAP网站下一篇: IE浏览器下载rar等格式文件后自动打开的解决办法
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: ASP 代码 javascript
相关日志:
评论: 1 | 引用: 0 | 查看次数: 16754
发表评论