Advertisement
4_2005-2006 String Manipulation #159338

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.

AI

Resumo por IA: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Código fonte
original-source
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 = "&nbsp;"
	RemoveHTML = sHTML
End function
Comentários originais (3)
Recuperado do Wayback Machine