A Symfony utility for cleaning up the HTML that users submit
Tom Boutell explains some features that are hidden in his pkToolkitPlugin plugin for Symfony:
* The pkHtml class. Many projects allow users to edit content via a rich text editor. And we all know what happens if the user pastes a Word document in there: the styles of the page wind up hopelessly munged. You can use striptags(), but that doesn’t clean up the CSS, so your page is still a mess.
A common workaround is to use FCK’s “paste as plaintext” mode, which thwarts attempts to paste rich text from another program. That works, after a fashion, but it’s frustrating for users. And none of the workarounds help if the user is actively trying to enter inappropriate HTML in a misguided attempt to re-style their site… then calling you to fix it for the 500th time.
HTML Tidy can do the job, but it has a reputation for being heavy and slow.
Or… you can just use pkHtml::simplify():