|
 |  |  |  | |
 | | Reviews Written By This User | |  |
List of All Reviews Written By Eric Fogleman from Sacramento, CA:
Great Code, which I enhanced a little  Written by Eric Fogleman from Sacramento, CA (Monday, November 28, 2005) Writer is with: http://www.google.com
 |
Listing Reviewed: Strip HTML Strengths: Filters out HTML well and is quick and to the point Weaknesses: Doesn't loop to replace all instances Details: I modified it slightly to add a loop to remove all instances of HTML, within the passed string.
'**************************************
' Name: Strip HTML
' Description:Strips any HTML tags from
' a string and returns the results. I use
' this for data that users submit through
' forms to prevent them from using HTML.
' By: Lewis E. Moten III
'
' Inputs:asHTML - the string that may contain HTML code
'
' Returns:Returns a string that has been stripped of HTML code.
'
' Assumes:This function assumes that you
' have vbScript 5.0 or higher installed.
'
' Side Effects:Your page will come up with errors if you do not have vbScript 5.0
' or higher installed on your server (or on the client browser
' if that is where it is being used)
'
' This code is copyrighted and has limited warranties. Please see
' http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=6269&lngWId=4
' for details.
'**************************************
Function StripHTML(ByRef asHTML)
Dim loRegExp ' Regular Expression Object
Dim theOutString ' string for output
Dim theLastStringVal ' out string copy for loop comparison
Dim filteringComplete ' flag for filtering loop
' Create built In Regular Expression object to look for HTML tags
Set loRegExp = New RegExp
loRegExp.Pattern = "<[^>]*>"
' Set the out string
theOutString = asHTML
' Loop through the out string looking for HTML and strip it
filteringComplete = FALSE
While filteringComplete = FALSE
theOutString = loRegExp.Replace(theOutString, "")
If theLastStringVal = theOutString Then
filteringComplete = TRUE
End If
theLastStringVal = theOutString
WEnd
' Return the original String stripped of HTML
StripHTML = theOutString
' Release object from memory
Set loRegExp = Nothing
End Function Review Based On: 1 Hour(s) of usage |
|