Installation (only php5 package)
If you are using PHP5 on a Windows system, all you need to do to enable the extension is uncomment the line extension=php_tidy.dll in your php.ini file. The official win32 binary distribution has built-in Tidy support.
If you are using PHP5 on Debian Linux system, all you need to do to enable the extension is run command in console terminal:
~ # apt-get install php5-tidy
If we need to recover bad html code or we doubt that the user enters the correct code in one of the proposed fields, then we can always be insured by Tidy.
It's very simple, this is a bad html code:
- $html = "<html>
<p> bad code <br> second bad code </i>
For repair it, all you need to do is:
So you add some short configurations params (wrapper, output standart and indent), than create a new Tidy object, than parse your bad string with encoding param and finaly run method Tidy::cleanRepair().
We can see a results:
We see that tag </i> was deleted, tag <br /> was modified, tag <p> was closed correctly and also was added a DOCTYPE tag. And now the page looks more attractive.
All documentation about Tidy you can find on php.net in Tidy section.