2
votes

I copied a function that strips html and added some extra replaces into the code, but when I call this function in anywhere I get error with this code

stripHTML(objRS("Name")) input are strings, how do I switch or declear the type?

Microsoft VBScript runtime error '800a000d' Type mismatch: '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 &lt; and &gt;
  strOutput = Replace(strOutput, "<", "&lt;")
  strOutput = Replace(strOutput, ">", "&gt;")
  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

UPDATE

The place I am calling this function is another file that has this page included at top

sometimes this function will be called by another file THIS page is pulling (example : footer template)

How do I make this function Globally accessible?

1
objRS("Name") may be NULL. You could guard against this in your SQL query: select isnull(Name, '') ... - Bond
They have values this is inside do while not objRS.EOF and convert code from something already working. @Bond - vico

1 Answers

1
votes

As has been pointed out you will still need to deal with NULL(s) but otherwise try:

stripHTML(CStr(objRS("Name")))