⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ubb代码的使用.asp

📁 较为详细的介绍了asp自定义的各种函数,方便asp的各种开发.
💻 ASP
📖 第 1 页 / 共 2 页
字号:
<% 

Function icode2Html(str,unimage,unsound) 
if not str<>"" then exit function '若是空串结束 
str=HTMLEncode(str) '先对文本进行HTML编码 
str=replace(str,chr(13)+chr(10),"<br>") '将文本回车换行符换成HTML的换行 
str=replace(str,chr(32),"&nbsp;") '把文本空格换成HTML空格 
tmpstr="icode" '此变量将用于处理[MYCODE]xxxxxx[/MYCODE]中的文本xxxxxx 
str=icodeStr2(str,"mycode") '调用icodeStr2函数,将出现[mycode]xxx[/mycode]的地方换成<pre>xxx</pre> 
str=icodeStr2(str,"url") '将[url]xxx[/url]换成<a href=xxx target=_blank>xxx</a> 
str=icodeStr2(str,"email") '类似上面 
if not unimage then str=icodeStr2(str,"image") '若没有禁用贴图 对其进行替换 <img src=xxx> 
str=icodeStr1(str,"url") '将[url=yyy]xxx[/url]换成<a href=yyy target=_blank>xxx</a> 
str=icodeStr1(str,"email") '类似上面替换成EMAIL链接 
str=icodeStr1(str,"color") '替换成<font color=xxx>...</font> 
if not unsound then str=icodeStr1(str,"sound") 
'若没有禁用贴歌,则替换成<embed ..>什么的 
if not unsound then str=icodeStr1(str,"flash") 
'若没有禁用贴歌,则替换成<embed ..>什么的 
str=replace(str,"[b]","<b>",1,-1,1) '加粗 
str=replace(str,"[/b]","</b>",1,-1,1) 
str=replace(str,"[i]","<i>",1,-1,1) '倾斜 
str=replace(str,"[/i]","</i>",1,-1,1) 
str=replace(str,"[u]","<u>",1,-1,1) '加下划线 
str=replace(str,"[/u]","</u>",1,-1,1) 
str=replace(str,"[br]","<br>",1,-1,1) '换行 
str=replace(str,"["&tmpstr,"[",1,-1,1) '把mycode中出现的[yyy]...[/yyy]原样显示出来,不明白哦,看后面吧 
str=replace(str,tmpstr&"]","]",1,-1,1) 
str=replace(str,"/"&tmpstr,"/",1,-1,1) 
icode2Html=str '把处理好的文本返回 
End Function 

'idodeStr1函数处理的是UBB格式为[UBB标记=xxxxxx][/UBB标记] 
function icodeStr1(icode_str,icodeKeyWord) 
beginstr=1 '记录开始的字符位置的变量 
endstr=1 '记录结束的字符位置的变量 

'下面对文本(字符串)中出现的icodeKeyWord 即ubb标记,进行查找替换,为方便解释我们以 文本内容="yyy[url=xxx][/url]zzz" 为例 
do while icodeKeyWord="url" or icodeKeyWord="email" or icodeKeyWord="color" or icodeKeyWord="sound" or icodeKeyWord="flash" 
beginstr=instr(beginstr,icode_str,"["&icodeKeyWord&"=",1) 
'找到文本中出现 "[url=" 的位置,本例值为4 
if beginstr=0 then exit do '如果为0说明没有这个标记则退出循环 
endstr=instr(beginstr,icode_str,"]",1) '如果有,则从4开始的地方找接下来的"]",它的位置记录在endstr中,本例中值该为12 
if endstr=0 then exit do '如果没有"]"则退出 
laststr=instr(beginstr,icode_str,"[/"&icodeKeyWord&"]",1) 
'从刚刚4的位置开始,找文本中出现的匹配的一对即"[/url]",如果不存在则退出 
if laststr=0 then exit do '如果没有退出 
LicodeKeyWord=icodeKeyWord '把UBB标记用另一个变量保存下来 
beginstr=beginstr+len(LicodeKeyWord)+2 '开始的位置加上ubb标记的长度还要加2,其实是要得到xxx的开始位置 
text=mid(icode_str,beginstr,endstr-beginstr) '取出xxx放在text中 
if icodeKeyWord="flash" then 
'对于flash只允许贴后缀名为.swf 
swf=instr(1,text,".swf",1) 
if swf=0 then exit do 
end if 
if icodeKeyWord="sound" then 
'对于sound允许贴下面几种格式 
mp3=instr(1,text,".mp3",1) 
wav=instr(1,text,".wav",1) 
wma=instr(1,text,".wma",1) 
asf=instr(1,text,".asf",1) 
midi=instr(1,text,".mid",1) 
if mp3=0 and wav=0 and wma=0 and asf=0 and midi=0 then exit do 
end if 
select case icodeKeyWord 
case "url" 
icode_str=replace(icode_str,"[url="&text&"]","<a href='"&text&"' target='_blank'>",1,1,1) '这个就开始做替换了,这里的text内容就是"xxx" 
icode_str=replace(icode_str,"[/url]","</a>",1,1,1) '替换配对的一半 
case "email" '如上 
icode_str=replace(icode_str,"[email="&text&"]","<a href='mailto:"&text&"'>",1,1,1) 
icode_str=replace(icode_str,"[/email]","</a>",1,1,1) 
case "color" 
icode_str=replace(icode_str,"[color="&text&"]","<font color='"&text&"'>",1,1,1) 
icode_str=replace(icode_str,"[/color]","</font>",1,1,1) 
case "sound" 
'替换的样子,除了嵌入插件,还包括下载该声音文件的超链接 
icode_str=replace(icode_str,"[sound="&text&"]","<embed width='70' height='25' autostart='0' loop='0' src='"&text&"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='"&text&"' target='_blank'>&nbsp;下载&nbsp;</a>",1,1,1) 
icode_str=replace(icode_str,"[/sound]","<br>",1,1,1) 
case "flash" 
'对于.swf文件,除了用嵌入尺寸更大的插件来播放,还允许开大窗口来欣赏 
icode_str=replace(icode_str,"[flash="&text&"]","<embed width='160' height='160' play='0' loop='0' src='"&text&"'><br><br>&nbsp;&nbsp;&nbsp;画面点右键选择PLAY播放&nbsp;&nbsp;&nbsp;&nbsp;<a href='"&text&"' target='_blank'>开新窗口欣赏</a>",1,1,1) 
icode_str=replace(icode_str,"[/flash]","<br>",1,1,1) 

end select 
loop '循环找下一次出现的该ubb标记做处理 
icodestr1=icode_str '换好的文本返回 
end function 

'idodeStr2函数处理的是UBB格式为[UBB标记]xxxxxx[/UBB标记] 
function icodeStr2(icode_str,icodeKeyWord) 
tmpstr="icode" 此变量将用于[MYCODE]xxxxxx[/MYCODE]中,处理文本xxxxxx 
beginstr=1 '和上面一样 
endstr=1 

do while icodeKeyWord="url" or icodeKeyWord="email" or icodeKeyWord="image" or icodeKeyWord="mycode" 
'下面不多做解释了,很多和上面是类似的 
beginstr=instr(beginstr,icode_str,"["&icodeKeyWord&"]",1) 
if beginstr=0 then exit do 
endstr=instr(beginstr,icode_str,"[/"&icodeKeyWord&"]",1) 
if endstr=0 then exit do 
LicodeKeyWord=icodeKeyWord 
beginstr=beginstr+len(licodeKeyWord)+2 
text=mid(icode_str,beginstr,endstr-beginstr) 
if icodeKeyWord="image" then 
gif=instr(1,text,".gif",1) 
jpg=instr(1,text,".jpg",1) 
if gif=0 and jpg=0 then exit do 
end if 
select case icodeKeyWord 
case "url" 
icode_str=replace(icode_str,"[url]"&text,"<a href='"&text&"' target='_blank'>"&text,1,1,1) 
icode_str=replace(icode_str,"[/url]","</a>",1,1,1) 
case "email" 
icode_str=replace(icode_str,"[email]"&text," <a href='mailto:"&text&"'>"&text,1,1,1) 
icode_str=replace(icode_str,"[/email]","</a>",1,1,1) 
case "image" 
'贴图时最怕别人的图片太大而影响界面的美观,我把图片嵌入表格的做法,而且表格宽度自适应后固定下来,就不怕了 
icode_str=replace(icode_str,"[image]"&text,"<table width='100%' align=center border='0' cellspacing='0' cellpadding='0' style='table-layout: fixed'><tr><td><a href='"&text&"' target=_blank><img src="&text,1,1,1) 
icode_str=replace(icode_str,"[/image]"," border=0 alt='点击打开新窗口'></a></td></tr></table>",1,1,1) 
case "mycode" 
'这段是处理[mycode]xxxxxx[/mycode],我们要考虑处理的是如果xxxxxx中出现[url]...[/url]这样的标记怎么办,为避免它们被替换,大家看到,在函数icode2Html中我们要先做mycode的处理,这点非常重要,我的思路是把xxxxxx中出现的"[url]...[/url]"先换成"[icodeurl]icode...[icode/icodeurl]icode",这样他们就不会被处理了,最后在函数icode2Html中,又把它们换回去 
codetext=replace(text,"[","["&tmpstr,1,-1,1) 
codetext=replace(codetext,"]",tmpstr&"]",1,-1,1) 
codetext=replace(codetext,"/","/"&tmpstr,1,-1,1) 
icode_str=replace(icode_str,"[mycode]"&text,"<pre style='position:relative;color: #003366; background-color: #C5CFDC;padding:10 10 10 10;margin:15'>"&codetext,1,1,1) 
icode_str=replace(icode_str,"[/mycode]","</pre>",1,1,1) 
end select 
loop '循环找下一次出现的该ubb标记做处理 

icodestr2=icode_str '换好的文本返回 
end function 
%> 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -