This function takes in a block of HTML block, however messy, and attempts to create a printable version of it, removing all the non-printable tags. This tag is ideal for converting HTML snippets to simple text-only representations.
Contents |
HtmlGetPrintableText( htmlblock )
This function returns the text-only tag-free representation of the HTML block
<cfsavecontent variable="htmlBlock"> <p><span class="mt-enclosure mt-enclosure-image" style="display: inline;"> <img alt="IEPins.jpg" src="http://uk.gizmodo.com/IEPins.jpg" width="356" height="308" class="mt-image-none" style="" /> </span> <p>If you're using Internet Explorer to read this it might be an idea to shut it down now and open up trusty old FireFox instead.</p> <p>Microsoft has today issued an alert to notify users of a critical security flaw in IE.7.0 that could allow hackers to take control of your computer and steal passwords. The company is apparently preparing an emergency patch to fix it but in the meantime simply requests that users remain 'vigilant' against the threat.</p> </cfsavecontent> <cfset g = HtmlGetPrintableText( htmlBlock )> // would result in If you're using Internet Explorer to read this it might be an idea to shut it down now and open up trusty old FireFox instead. Microsoft has today issued an alert to notify users of a critical security flaw in IE.7.0 that could allow hackers to take control of your computer and steal passwords. The company is apparently preparing an emergency patch to fix it but in the meantime simply requests that users remain 'vigilant' against the threat.
This is a highly efficient way of converting HTML text without using any complicated underlying DOM or SAX processing, or regex. It has been designed to be very tolerant of poorly formatted HTML.
This is a very useful function for those that wish to pre-process user input forms that may result in some adding in HTML text that may break the rendering of your application. For example, inserting HTML into their display name in a CMS system.