Mimic PHP’s strip_tags() function with ASP

by admin on July 24, 2009 · 0 comments

PHP has a great function called 'strip_tags'. You pass it a string of HTML, and it removes all formatting and tags, and returns only the text portion. Here's the equivalent in ASP, using regular expressions to do the finding and replacing of HTML tags.

'====
Function stripTags( strToStrip )
'====
    Dim objRegExp
   
    strToStrip = Trim( strToStrip & "" )
    If Len( strToStrip ) > 0 Then
        Set objRegExp = New RegExp
        objRegExp.IgnoreCase = True
        objRegExp.Global = True
        objRegExp.Pattern= "<[^>]+>"
        strToStrip = objRegExp.Replace(strToStrip, "")
        Set objRegExp = Nothing
    End If
    StripHTMLTags =  strToStrip
End Function

Previous post:

Next post: