【发布时间】:2014-09-25 02:56:23
【问题描述】:
我复制了一个剥离 html 的函数,并在代码中添加了一些额外的替换,但是当我在任何地方调用此函数时,此代码出现错误
stripHTML(objRS("Name"))输入为字符串,如何切换或清除类型?
Microsoft VBScript 运行时错误“800a000d”类型不匹配:“stripHTML”
--function.asp
function stripHTML(strHTML)
Dim objRegExp, strOutput, tempStr
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "<(.|n)+?>"
'Replace all HTML tag matches with the empty string
strOutput = objRegExp.Replace(strHTML, "")
'Replace all < and > with < and >
strOutput = Replace(strOutput, "<", "<")
strOutput = Replace(strOutput, ">", ">")
strOutput = Lcase(replace(replace(trim(strOutput),"/","-")," ","-"))
strOutput = replace(replace(replace(strOutput,".","-"),"&","-"),",","")
strOutput = replace(replace(strOutput,"--","-"),"---","-")
stripHTML = strOutput 'Return the value of strOutput
Set objRegExp = Nothing
end Function
更新
我调用这个函数的地方是另一个在顶部包含这个页面的文件
有时这个函数会被另一个文件调用这个页面正在拉取(例如:页脚模板)
如何使此功能可全局访问?
【问题讨论】:
-
objRS("Name")可能为 NULL。您可以在 SQL 查询中防范这种情况:select isnull(Name, '') ... -
它们的值在
do while not objRS.EOF内部,并从已经工作的东西转换代码。 @邦德
标签: vbscript