Tools Links Login

Remove HTML + Optional Ingnore Tags

This function will strip a string of all html. An optional parameter (sIgnoreTags) allows specified HTML tags to be ignored from stripping.

Original Author: David Garske

Code

Function RemoveHTML(ByVal sHTML, ByVal sIgnoreTags)
Dim I, J, arr_sIgnoreTags, sIgnoreTag, bIgnoreTags, bIgnoreTag, iIndex
bIgnoreTags = False
If Len(sIgnoreTags) > 0 Then
arr_sIgnoreTags = Split(sIgnoreTags, ",")
bIgnoreTags = True
End If
sHTML = Trim(sHTML)
If IsNull(sHTML) Then sHTML = ""
sHTML = Replace(sHTML, vbCrLf, "") 'Makes easier
I = InStr(1, sHTML, "<")
Do While I <> 0
bIgnoreTag = False
If bIgnoreTags Then
For iIndex = 0 To UBound(arr_sIgnoreTags)
sIgnoreTag = Trim(arr_sIgnoreTags(iIndex))
If UCase(Mid(sHTML, I + 1, Len(sIgnoreTag))) = UCase(sIgnoreTag) Then
bIgnoreTag = True
Exit For
End If
Next
End If

If Not bIgnoreTag Then
J = InStr(I + 1, sHTML, ">")
If J <> 0 Then
sHTML = Left(sHTML, I - 1) & Mid(sHTML, J + 1)
Else
'Chop off rest off sHTML since bad HTML
sHTML = Left(sHTML, I - 1)
End If
Else
I = I + 1 'So next tag is searched
End If
I = InStr(I, sHTML, "<")
Loop
If Len(sHTML) = 0 Then sHTML = " "
RemoveHTML = sHTML
End function

About this post

Posted: 2003-06-01
By: ArchiveBot
Viewed: 99 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.