欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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