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 <">
