jb51用的ubb转换 原创
程序员文章站
2022-03-27 10:01:16
ubbcode.asp复制代码 代码如下:<% function ubbcode(strcontent) if isempty(strconten...
ubbcode.asp
<%
function ubbcode(strcontent)
if isempty(strcontent) or isnull(strcontent) then
exit function
else
dim regex,strmatch
set regex=new regexp
regex.ignorecase =true
regex.global=true
regex.pattern="\[html\]((\r\n)?([\s\s]+?))\[\/html\]"
set strmatchs=regex.execute(strcontent)
for each strmatch in strmatchs
'response.write strmatch.submatches(3)
randomize
rndid="runcode"&int(100000 * rnd)
strcontent=replace(strcontent,strmatch.value,"<br/><font color=red>html代码:</font><textarea style=""width:96%; height:300px;"" id="""&rndid&""" class=""htmlarea"">"&ubbfilter(htmldecode(strmatch.submatches(2)))& "</textarea><br/><input onclick=""runex('"&rndid&"')"" type=""button"" value=""运行此代码""/> <input onclick=""docopy("&rndid&")"" type=""button"" value=""复制此代码""/> <input onclick=""dosave("&rndid&")"" type=""button"" value=""保存代码""/><br/> [ctrl+a 全部选择 提示:你可先修改部分代码,再按运行]")
next
set strmatchs=nothing
'去空行
regex.pattern="\n[\s]*\r"
set strmatchs=regex.execute(strcontent)
for each strmatch in strmatchs
strcontent=replace(strcontent,strmatch.value,"")
next
'代码块
regex.pattern="\[code\]((\r\n)?([\s\s]+?))\[\/code\]"
set strmatchs=regex.execute(strcontent)
for each strmatch in strmatchs
randomize
rndid="code"&int(100000 * rnd)
strcontent=replace(strcontent,strmatch.value,"<br/><div style=""float:left""><font color=green>code代码:</font></div><div style=""float:right;text-align:right;"">[<a href=""javascript:void(null)"" onclick=""docopy("&rndid&")"">复制此代码</a>]</div><br/><div class=""codetextarea"" id="""&rndid&""">"&strmatch.submatches(2)&"</div>")
next
set strmatchs=nothing
'实现插入影音文件
regex.pattern="\[(swf|wma|wmv|rm|ra|qt)(=\d*?|)(,\d*?|)\]([^<>]*?)\[\/(swf|wma|wmv|rm|ra|qt)\]"
set strmatchs=regex.execute(strcontent)
dim strtype,strwidth,strheight,strsrc,titletext
for each strmatch in strmatchs
randomize
strtype=strmatch.submatches(0)
if strtype="swf" then
titletext="<img src=""../images/flash.gif"" alt="""" style=""margin:0px 2px -3px 0px"" border=""0""/>flash动画"
elseif strtype="wma" then
titletext="<img src=""../images/music.gif"" alt="""" style=""margin:0px 2px -3px 0px"" border=""0""/>播放音频文件"
elseif strtype="wmv" then
titletext="<img src=""../images/mediaplayer.gif"" alt="""" style=""margin:0px 2px -3px 0px"" border=""0""/>播放视频文件"
elseif strtype="rm" then
titletext="<img src=""../images/realplayer.gif"" alt="""" style=""margin:0px 2px -3px 0px"" border=""0""/>播放real视频流文件"
elseif strtype="ra" then
titletext="<img src=""../images/realplayer.gif"" alt="""" style=""margin:0px 2px -3px 0px"" border=""0""/>播放real音频流文件"
elseif strtype="qt" then
titletext="<img src=""../images/mediaplayer.gif"" alt="""" style=""margin:0px 2px -3px 0px"" border=""0""/>播放mov视频文件"
end if
strwidth=strmatch.submatches(1)
strheight=strmatch.submatches(2)
if (len(strwidth)=0) then
strwidth="400"
else
strwidth=right(strwidth,(len(strwidth)-1))
end if
if (len(strheight)=0) then
strheight="300"
else
strheight=right(strheight,(len(strheight)-1))
end if
strsrc=strmatch.submatches(3)
rndid="temp"&int(100000 * rnd)
strcontent= replace(strcontent,strmatch.value,"<div class=""ubbpanel""><div class=""ubbtitle"">"&titletext&"</div><div class=""ubbcontent""><a id="""+rndid+"_href"" href=""javascript:mediashow('"+strtype+"','"+rndid+"','"+strsrc+"','"+strwidth+"','"+strheight+"')""><img name="""+rndid+"_img"" src=""../images/mm_snd.gif"" style=""margin:0px 3px -2px 0px"" border=""0"" alt=""""/><span id="""+rndid+"_text"">在线播放</span></a><div id="""+rndid+"""></div></div></div>")
next
set strmatchs=nothing
regex.pattern="(\[mid\])(.[^\]]*)\[\/mid\]"
strcontent= regex.replace(strcontent,"<embed src=""$2"" height=""45"" width=""314"" autostart=""0""></embed>")
regex.pattern="<br>([\s| | ]*)?<br>"
strcontent=regex.replace(strcontent,"<br>")
strcontent=replace(strcontent,"&","&")
strcontent=replace(strcontent,"'","'")
strcontent=replace(strcontent,"","") '因为以前上传图片
set regex=nothing
end if
ubbcode=strcontent
end function
%>
基本上来自pjhome
复制代码 代码如下:
<%
function ubbcode(strcontent)
if isempty(strcontent) or isnull(strcontent) then
exit function
else
dim regex,strmatch
set regex=new regexp
regex.ignorecase =true
regex.global=true
regex.pattern="\[html\]((\r\n)?([\s\s]+?))\[\/html\]"
set strmatchs=regex.execute(strcontent)
for each strmatch in strmatchs
'response.write strmatch.submatches(3)
randomize
rndid="runcode"&int(100000 * rnd)
strcontent=replace(strcontent,strmatch.value,"<br/><font color=red>html代码:</font><textarea style=""width:96%; height:300px;"" id="""&rndid&""" class=""htmlarea"">"&ubbfilter(htmldecode(strmatch.submatches(2)))& "</textarea><br/><input onclick=""runex('"&rndid&"')"" type=""button"" value=""运行此代码""/> <input onclick=""docopy("&rndid&")"" type=""button"" value=""复制此代码""/> <input onclick=""dosave("&rndid&")"" type=""button"" value=""保存代码""/><br/> [ctrl+a 全部选择 提示:你可先修改部分代码,再按运行]")
next
set strmatchs=nothing
'去空行
regex.pattern="\n[\s]*\r"
set strmatchs=regex.execute(strcontent)
for each strmatch in strmatchs
strcontent=replace(strcontent,strmatch.value,"")
next
'代码块
regex.pattern="\[code\]((\r\n)?([\s\s]+?))\[\/code\]"
set strmatchs=regex.execute(strcontent)
for each strmatch in strmatchs
randomize
rndid="code"&int(100000 * rnd)
strcontent=replace(strcontent,strmatch.value,"<br/><div style=""float:left""><font color=green>code代码:</font></div><div style=""float:right;text-align:right;"">[<a href=""javascript:void(null)"" onclick=""docopy("&rndid&")"">复制此代码</a>]</div><br/><div class=""codetextarea"" id="""&rndid&""">"&strmatch.submatches(2)&"</div>")
next
set strmatchs=nothing
'实现插入影音文件
regex.pattern="\[(swf|wma|wmv|rm|ra|qt)(=\d*?|)(,\d*?|)\]([^<>]*?)\[\/(swf|wma|wmv|rm|ra|qt)\]"
set strmatchs=regex.execute(strcontent)
dim strtype,strwidth,strheight,strsrc,titletext
for each strmatch in strmatchs
randomize
strtype=strmatch.submatches(0)
if strtype="swf" then
titletext="<img src=""../images/flash.gif"" alt="""" style=""margin:0px 2px -3px 0px"" border=""0""/>flash动画"
elseif strtype="wma" then
titletext="<img src=""../images/music.gif"" alt="""" style=""margin:0px 2px -3px 0px"" border=""0""/>播放音频文件"
elseif strtype="wmv" then
titletext="<img src=""../images/mediaplayer.gif"" alt="""" style=""margin:0px 2px -3px 0px"" border=""0""/>播放视频文件"
elseif strtype="rm" then
titletext="<img src=""../images/realplayer.gif"" alt="""" style=""margin:0px 2px -3px 0px"" border=""0""/>播放real视频流文件"
elseif strtype="ra" then
titletext="<img src=""../images/realplayer.gif"" alt="""" style=""margin:0px 2px -3px 0px"" border=""0""/>播放real音频流文件"
elseif strtype="qt" then
titletext="<img src=""../images/mediaplayer.gif"" alt="""" style=""margin:0px 2px -3px 0px"" border=""0""/>播放mov视频文件"
end if
strwidth=strmatch.submatches(1)
strheight=strmatch.submatches(2)
if (len(strwidth)=0) then
strwidth="400"
else
strwidth=right(strwidth,(len(strwidth)-1))
end if
if (len(strheight)=0) then
strheight="300"
else
strheight=right(strheight,(len(strheight)-1))
end if
strsrc=strmatch.submatches(3)
rndid="temp"&int(100000 * rnd)
strcontent= replace(strcontent,strmatch.value,"<div class=""ubbpanel""><div class=""ubbtitle"">"&titletext&"</div><div class=""ubbcontent""><a id="""+rndid+"_href"" href=""javascript:mediashow('"+strtype+"','"+rndid+"','"+strsrc+"','"+strwidth+"','"+strheight+"')""><img name="""+rndid+"_img"" src=""../images/mm_snd.gif"" style=""margin:0px 3px -2px 0px"" border=""0"" alt=""""/><span id="""+rndid+"_text"">在线播放</span></a><div id="""+rndid+"""></div></div></div>")
next
set strmatchs=nothing
regex.pattern="(\[mid\])(.[^\]]*)\[\/mid\]"
strcontent= regex.replace(strcontent,"<embed src=""$2"" height=""45"" width=""314"" autostart=""0""></embed>")
regex.pattern="<br>([\s| | ]*)?<br>"
strcontent=regex.replace(strcontent,"<br>")
strcontent=replace(strcontent,"&","&")
strcontent=replace(strcontent,"'","'")
strcontent=replace(strcontent,"","") '因为以前上传图片
set regex=nothing
end if
ubbcode=strcontent
end function
%>
基本上来自pjhome
上一篇: 正则表达式的语法
推荐阅读
-
SEO经验之谈:用原创文章提升转化率的几个要点介绍
-
用C#把文件转换为XML的代码
-
常用到用css3实现的转换,过渡和动画
-
发一个php简单的伪原创程序,配合商城采集用的
-
用Excel 数据透视表的多表合并功能轻易完成表格转换
-
如何将含有图片的PPT转换成Word用Word格式查看
-
用Python实现换行符转换的脚本的教程
-
强烈推荐,超详细,实操零失误:node.js安装 + npm安装教程 + Vue开发环境搭建 【非原创,但是用生命推荐的转载】
-
用jQuery将JavaScript对象转换为querystring查询字符串的方法
-
PHP实现字节数Byte转换为KB、MB、GB、TB的方法 原创