保存为CHAR.inc文件
<%
function htmlencode(str)
dim result
if isNULL(str) then
htmlencode=""
exit function
end if
result=str
result = replace(result, "&", "&")
result = replace(result, ">", ">")
result = replace(result, "<", "<")
result = replace(result, chr(34),""")
result = replace(result,chr(32)," ",1)
result = replace(result, chr(13)&chr(10), "<BR>",1)
HTMLEncode = result
end function
function HTMLDecode(str)
dim result
if isNULL(str) then
htmlencode=""
exit function
end if
result=str
result = replace(result, ">", ">")
result = replace(result, "<", "<")
result = replace(result," ",chr(32))
result = replace(result, """,chr(34))
result = replace(result, "<BR>", chr(13)&CHR(10))
result = replace(result, "&","&" )
HTMLDecode = result
end function
%>
我的思路是这样的,如果能用正则表达式最好,
不能用可以这么试试(没有测试,很可能有语法错误):
function CutHTMLTag(strHaveHTML)
dim nBeginPos,nEndPos,strHaveHTML,strHTMLTag
strHaveHML="这是一个<STRONG>测试</STRONG>字符串,需要被删除HTML标记"
do while true
nBeginPos=InStr(1,strHaveHTML,"<") '得到HTML标记中"<"的位置
if nBeginPos<1 then '如果没找到,说明已经没有HTML标记了
CutHTMLTag=strHaveHTML
exit function
else
nEndPos=InStr(1,strHaveHTML,">") '得到HTML标记中的">"位置
if nEndPos<1 then '如果没找到,退出
CutHTMLTag=strHaveHTML
exit function
else
strHTMLTag=Mid(strHaveHTMLTag,nBeginPos,nEndPos-nBeginPos) '得到HTML标记
'注意:这里并不严谨,没有判断得到的strHTMLTag是否真为HTML标记,实现的是否可以和现有的所有HTML标记一一比较
StrHaveHTML=Replace(strHaveHTML,strHTMLTag,"") '将该HTML标记用空字符串代替
end if
end if
loop
end function
<SCRIPT LANGUAGE="VBScript">
<!--
content="<html><head><title>内容编辑</title></head><body>内容111111</body></html>"
function RemoveHTML(fString)
dim re
set re = New RegExp
re.Global = True
re.IgnoreCase = True
're.MultiLine = True
if not isnull(fString) then
re.Pattern = "<(.[^>]*)>"
fString = re.Replace(fString,"")
RemoveHTML = fString
end if
end function