I try to use tidy to ensure any text coming in that is allowed to contain html in it won't break the rendering page (eg. has valid x/html), so here are the steps I used to install tidy on my box.
sudo apt-get install -y php5-dev libtidy-dev
sudo apt-get install -y subversion
svn co http://svn.php.net/repository/php/php-src/branches/PHP_5_3/ext/tidy/
cd tidy/
phpize
./configure
make
sudo make install
cd ../
rm -rf tidy/
Following this, I needed to add extension="tidy.so"
to my php.ini file. Then I
just restarted my server and I was good-to-go.
Update (Monday, July 15, 2013)
It seems the repo http://svn.php.net/repository/php/php-src/branches/PHP_5_3/ext/tidy/
no longer exists. If I find it, I'll set it up on a server and change the path in the above code. But until then, unfortunately the code above won't work :(
Update (20 minutes later on Monday, July 15, 2013)
Not going to test it because I don't have a clean environment to do so, but may be able to download http://pecl.php.net/package/tidy
, unzip and move the source directory in there around a bit to make the above code work.
Give that a go.
When I get around to it, I'll give it a test myself, and if it works, update the above steps accordingly.