debuggable

 
Contact Us
 

Cleaning Html with this HtmlCleaner for CakePHP

Posted on 14/12/08 by Tim Koschützki

Hey folks,

one of the problems we faced back when we merged our old blogs thinkingphp.org and php-coding-practices.com, was this little "Recent Comments" feature in the right navbar. It shows syntax-highlighted code, but makes use of Cake's TextHelper's truncate() method at the same time. The problem is obvious: Html can get cut off, totally screwing the page layout.

One day I sat down to solve this problem. The result of this is the following ViewHelper "HtmlCleaner", which could be an easy-to-use alternative for HtmlTidy.

You can find the code including tests on Debuggable Scraps / CakePHP / Helpers. Suggestions and feedback are always welcome.

Usage is very simple:

<?php
$bogusHtml = $htmlCleaner->clean($bogusHtml);
?>

Enjoy!

-- Tim Koschuetzki aka DarkAngelBGE

 
&nsbp;

You can skip to the end and add a comment.

Tim Koschützki said on Dec 14, 2008:

Okay Andy (AD7six) made me aware of the considerHtml option in the truncate method.

I wasn't aware of that, that's pretty cool. However, the helper can be used independent of TextHelper::truncate(). :]

This post is too old. We do not allow comments here anymore in order to fight spam. If you have real feedback or questions for the post, please contact us.