Home > Article > Web Front-end > How to remove html in asp
aspMethods to remove html: 1. Disable the html tag directly; 2. Use the "function RemoveHTML(){...}" method to remove; 3. Use IE or other tools to remove; 4. Remove through VBScript HTML code.
The operating environment of this article: Windows7 system, HTML5&&ASP3.0 version, Dell G3 computer.
ASP removes HTML code:
Method 1: Disable HTML
The easiest way is to directly disable html tags without removing them. You can use the Replace() function. For example:
strText = Replace(strText, "<script", "<script", 1, -1, 1)
Or directly disable all html:
strText = Replace(strText, "<", "<")
Although this is safe, it is not friendly enough. (The text submitted by the user will become difficult to read)
Method 2: Using "d21bf6265d53cdd4dcff18f6785f8fb4"
How to make the html tag disappear from the text? We can remove everything between "d21bf6265d53cdd4dcff18f6785f8fb4"
In JavaScript this is simple:
function RemoveHTML( strText ) { var regEx = /<[^>]*>/g; return strText.replace(regEx, ""); }
Now back to VBScript, for Scripting engine 5.0 or higher (the version can be verified by calling the ScriptEngineMajorVersion and ScriptEngineMinorVersion functions), we can also use the RegExp object:
Function RemoveHTML( strText ) Dim RegEx Set RegEx = New RegExp RegEx.Pattern = "<[^>]*>" RegEx.Global = True RemoveHTML = RegEx.Replace(strText, "") End Function
If regular expressions are not used, the following function can achieve the same purpose:
Function RemoveHTML( strText ) Dim nPos1 Dim nPos2 nPos1 = InStr(strText, "<") Do While nPos1 > 0 nPos2 = InStr(nPos1 + 1, strText, ">") If nPos2 > 0 Then strText = Left(strText, nPos1 - 1) & Mid(strText, nPos2 + 1) Else Exit Do End If nPos1 = InStr(strText, "<") Loop RemoveHTML = strText End Function
Although the above methods can remove the html tags in brackets, these methods have the following problems:
First, any angle brackets within the text that do not represent html will be removed. And the text between the two angle brackets will also be deleted. In other words, any "c304bc6269ed285572cb5e1d8fb5ffed" will produce unpredictable results.
In addition, this method cannot control which html tags are deleted. For example, a4b561c25d9afb9ac8dc4d70affff4195a8028ccc7a7e27417bff9f05adf5932 these harmless tags are usually allowed.
Method Three: Using IE or other tools
There are many disadvantages:
"It may be desirable to parse HTML files inside a Web server process in response to a browser page request. However, the WebBrowser control, DHTML Editing Control, MSHTML, and other Internet Explorer components may not function properly in an Active Server Pages (ASP) page or other application run in a Web server application." (http://support.microsoft.com/support/kb/articles/Q244/0/85.ASP?LN=EN-US&SD=gn&FR=0)
Method Four: VBScript
The following functions can be restricted to specific html tags
Introduction:
To control the deleted tag list, you can add/remove tags to the TAGLIST constant. For example, if you want to keep all 9368c5823948a595f9974a5e2b3bd3f1 tags, delete them from TAGLIST B. The current list contains all html tags and LAYER tags in MSDN. Each tag should be enclosed by ";".
The start tag and end tag will be deleted, such as "ad8f10e201a1f424c4faf26f5e875561" and 485d9ac889b9ade8704ce8893793719b
If the tag is in both the TAGLIST and BLOCKTAGLIST constants, all content between the start tag and the end tag will be deleted
Tags without closing tags are not considered html tags, and their content will not be deleted
If a block tag does not have an ending tag, all content from the beginning of this tag to the end of the text will be deleted
If the character following "