Strip HTML - ASP Function

Published in Website Design on Wednesday, 22 April 2009  |   Subscribe to rss feed for Strip HTML - ASP Function (rss logo graphic) Post RSS

Strip HTML From a String

This ASP function can be used to strip the HTML from a string - useful when listing summaries of items / pages in a database or displaying RSS feeds on your website.

Get The Code

Use the following function in your ASP code:

Function stripHTML(strHTML) 'Strips the HTML tags from strHTML


Dim objRegExp, strOutput
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 &lt; and &gt;
strOutput = Replace(strOutput, "<", "&lt;")
strOutput = Replace(strOutput, ">", "&gt;")
stripHTML = strOutput 'Return the value of strOutput
Set objRegExp = Nothing


End Function

Then call it on your page like this:

<%= stripHTML(theHtmlToStrip) %>

 


All resources written by The WebFertile Team.

Whatever your business needs, one of our highly trained small business development experts is sure to be able to help.