UBB 转换函数演示(6)_Dreamweaver教程

编辑Tag赚U币
教程Tag:暂无Tag,欢迎添加,赚取U币!

}
textarea {
border-width: 1; border-color: #000000;font-size: 12px;FONT-FAMILY: "Tahoma", "MS Shell Dlg";
}
</style>

<TEXTAREA name=phx cols=65 rows=12>
[i][b][color=blue]blue[/color][/b][/i]

[html][color=red]te
st[/color][/html]

[html][code]te
st[/code][/html]

[code][html]te
st[/html][/code]</textarea>
<br><button onclick=show.innerHTML=UBBCode(phx.value)>转换</button><br>
<div id=show style="border:1 solid skyblue;width=500;font-size: 12px;FONT-FAMILY:
'Tahoma', 'MS Shell Dlg';
"></div>


<script language=vbs>
strIcons = "1" '答应笑脸转换
strSmile="1" '同上
ImgName="em"
picurl="pic/"

function UBBCode(content)
'on error resume next
st=timer
set re=new regexp
re.global=true

re.pattern="\[code\](\r\n)?([\s\S] ?)\[\/code\]"
Set Matches = re.Execute(content) ' Execute search.
dim code()
n=0
if re.test(content) then codeb=true
if codeb then
For Each Match in Matches ' Iterate Matches collection.
redim Preserve code(n)
code(n) =Match.Value
n=n 1
Next
for i=0 to ubound(code)
if code(i)="" then exit for
content=replace(content,code(i),"{code"&i&"}")
next
end if


re.pattern="\[html\](\r\n)?([\s\S] ?)\[\/html\]"
Set Matches = re.Execute(content) ' Execute search.
dim html()
n=0
if re.test(content) then htmlb=true
if htmlb then
For Each Match in Matches ' Iterate Matches collection.
redim Preserve html(n)
html(n) =Match.Value
n=n 1
Next
for i=0 to ubound(html)
if html(i)="" then exit for
content=replace(content,html(i),"{html"&i&"}")
next
end if

content=gmt(content) 'ubb


if codeb then
for i=0 to ubound(code)
if code(i)="" then exit for
tcode=hencode(code(i))
content=replace(content,"{code"&i&"}",tcode)
next
end if
'-----
re.pattern="\[html\](\r\n)?([\s\S] ?)\[\/html\]"
Set Matches = re.Execute(content) ' Execute search.
dim html2()
n=0
if re.test(content) then html2b=true
if html2b then
For Each Match in Matches ' Iterate Matches collection.
redim Preserve html2(n)
html2(n) =Match.Value
n=n 1
Next
for i=0 to ubound(html2)
if html2(i)="" then exit for
content=replace(content,html2(i),"{html2"&i&"}")
next
end if


if htmlb then
for i=0 to ubound(html)
if html(i)="" then exit for
thtml=hencode(html(i))
content=replace(content,"{html"&i&"}",thtml)
next
end if

re.Pattern="(\[code\])(\r\n)?([\s\S] ?)(\[\/code\])"
content=re.Replace(content,"<PRE class=CodeSamp>$3</PRE>")

re.Pattern="(\[html\])(\r\n)?([\s\S] ?)(\[\/html\])"
content=re.Replace(content,"<span><TEXTAREA cols=95 rows=12>$3</TEXTAREA><br><INPUT onclick=runCode() type=button value=运行代码>[Ctrl A 全部选择 提示:你可先修改部分代码,再按运行]</span>")

来源:网上收集//所属分类:Dreamweaver教程/更新时间:2005-05-04
相关Dreamweaver教程