CFLib.org – Common Function Library Project

stripHTML(string)

Last updated October 4, 2010

Version: 4 | Requires: ColdFusion 5 | Library: StrLib

 
Rated 39 time(s). Average Rating: 3.0

Description:
Returns the string with all HTML removed. Unlike HTMLEditFormat which escapes HTML, this function actually removes the HTML.

Return Values:
Returns a string.

Example:

view plain print about
<CFSET str="the <B>dog</B> jumped over the <A HREF=""foo.html"">fox</A>.">
<CFOUTPUT>
Given str=#str#<BR>
The StripHTML version is #StripHTML(str)#
</CFOUTPUT>

Parameters:

Name Description Required
string String to be modified. Yes

Full UDF Source:

view plain print about
<cfscript>
/**
 * Removes HTML from the string.
 * v2 - Mod by Steve Bryant to find trailing, half done HTML.        
 * v4 mod by James Moberg - empties out script/style blocks
 * 
 * @param string      String to be modified. (Required)
 * @return Returns a string. 
 * @author Raymond Camden (ray@camdenfamily.com) 
 * @version 4, October 4, 2010 
 */

function stripHTML(str) {
    str = reReplaceNoCase(str, "<*style.*?>(.*?)</style>","","all");
    str = reReplaceNoCase(str, "<*script.*?>(.*?)</script>","","all");

    str = reReplaceNoCase(str, "<.*?>","","all");
    //get partial html in front
    str = reReplaceNoCase(str, "^.*?>","");
    //get partial html at end
    str = reReplaceNoCase(str, "<.*$","");
    return trim(str);
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

CF Ninja CF Ninja added
calcIRR
13 day(s) ago

Stephen Withington Stephen Withington added
getWeekOfMonth
13 day(s) ago

Adam Cameron Adam Cameron added
createPrimeNumbe...
a while ago

Ray Ford Ray Ford added
timeZoneNow
a while ago

Top Rated

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 48 time(s)

Barney Boisvert indentXml
Rated 5.0, 12 time(s)

Rachel Lehman deAccent
Rated 5.0, 9 time(s)

Darwan Leonardo Sitepu splitNumber
Rated 5.0, 8 time(s)

Created by Raymond Camden / Design by Justin Johnson