|
This excellent tutorial will show you how to strip any HTML tags from a string and return the results. Author: Lewis Moten Code: VBScript |
| |
Overall Rating:
 User Rated
| |
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
 |
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 |
HTML stripper works good  Written by Anonymous User (#1551-135) from Charlottesville, VA, USA (Wednesday, March 19, 2003)
 |
Strengths: Simple Example Weaknesses: Does not offer Reg Expression that can retrieve page title etc... Details: I'm working on a spider application. This code was very helpful as I have no prior experience with Regular Expressions. If you want to retrieve page title you'll need to write your own function and call it before running this. Review Based On: 1 Hour(s) of usage |
| |
|