ColdFusion Tutorial

Strip out all HTML from a variable

If you need to strip out all HTML from a variable, use this code:

<cfset your_variable = "<body>Strip out all HTML from a variable</body>">

<cfset StrippedVariable = REReplaceNoCase(your_variable, "<[^>]*>", "", "All")>

<cfoutput>#StrippedVariable#</cfoutput>


This will give the following output:

Strip out all HTML from a variable

 

See also:

HTMLEditFormat
Returns HTML escaped string. All carriage returns are removed from string, and all special characters (> < " &) are escaped.


HTMLCodeFormat
Returns HTML escaped string enclosed in <PRE> and </PRE> tags. All carriage returns are removed from string, and all special characters (> < " &) are escaped.


Or this custom tag:SafeText
SafeText is a custom tag that let the user enter HTML code in a text form. The tag will replace all HTML code with their appropriate entity-references.

ColdFusion Tutorial test

Strip out all HTML from a variable

No test is available or implemented for this ColdFusion Tutorial.

User Comments: 2

 use REReplaceNoCase()

Your example using replaceNoCase() does not work because the attributes are written as a Regular Expression - the proper tag is REReplaceNoCase(), which works great with your RegEx attributes.

 Nice try

Nice try but not quite that simple... the problem is nested angle tags.  Try the following:

<!-- <script>alert("hello");</script> -->

OR

<img src="foobar.gif" alt="> foobar <">

Add your comments

Your Name*:
Your Email:
Site URL:
Site Name:
Comemt Title*:
Your Comment*:
Key Phrase*:
q4Z
Your IP Address: 38.103.63.62
 

ScandicWeb is own by Scandic Systems LTD [UK] Company No. 5984000. All other trademarks and copyrights are the property of their respective holders.

[Home [Site Map [Privacy Statement [Site Feedback] [About ScandicWeb]


[ColdFusion [Flash [Search Engine Optimization [Graphics [Cascading Style Sheets (CSS) [JavaScript (JS) [Software]

Partner sites: ScandicSoft


Server time: 19. November 2008 Wednesday