jb51用的ubb转换 原创
程序员文章站
2022-07-02 19:35:45
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
上一篇: AI发展格局正从“数据”演变为“知识”
下一篇: 正则表达式的语法
推荐阅读
-
string '??54' (length=8)用什么函数能转换成int类型的?解决思路
-
用栈的数据结构实现综合计算器含中缀后缀计算及转换计算
-
自己写的一个UBB转换的函数_PHP
-
大写数字金额 用PHP实现小写金额转换大写金额的代码精确到分
-
能不能给讲讲Segmentfault 用的框架里的Data模式是怎么把数组转换成对象的?
-
用php实现gb2312和unicode间的编码转换
-
用php实现gb2312和unicode间的编码转换
-
用php自带的ImageMagick来实现PDF文件转换成图片
-
ae转换顶点工具怎么用? ae转换顶点工具的两种使用方法
-
asp下用实现模板加载的的几种方法总结 原创