Created
June 15, 2011 13:51
-
-
Save gwobcke/1027133 to your computer and use it in GitHub Desktop.
Classic ASP Strip HTML Function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% | |
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 < and > | |
strOutput = Replace(strOutput, "<", "<") | |
strOutput = Replace(strOutput, ">", ">") | |
stripHTML = strOutput 'Return the value of strOutput | |
Set objRegExp = Nothing | |
END FUNCTION | |
%> |
Sweet, I had one but this is much better. Thanks
If the string contains the string "<spec...>" it will be removed. I don't think it's a valid function.
Should we warn users not to use "<" and ">" individually?
The purpose of the function is to strip HTML markup from a defined string. It is not meant to be a parser of markup nor a markup validator, however providing a string like "This is a <strong><spec></strong> tag" would be invalid markup in any case and as such should already be correctly encoded like "This is a <strong><spec></strong> tag". EDIT: even these comments filter like this, hence my edit.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the function it works