Windows

How to setup (HTML) Tidy for PHP and Smarty in 5 minutes - WIN and Linux

Tidy is a PHP extension for the Tidy HTML clean and repair utility which allows you to not only clean and otherwise manipulate HTML documents, but also traverse the document tree. It's performance is great and you have a ton of features to make your html code or smarty output html compliant.

You can also use this plugin using another plugin in the PHP smarty template language.

Unfortunately tidy is not installed by default in most PHP distributions.

Here are the docs to set it up:

Tidy plugin installation on Windows

This is easy cheesy:

  1. download your tidy.dll at the PHP4.4 dist or the one for PHP5 or even php6

  2. copy this to your PHP extension dir e.g.

    E:

    mpp\php\extensions

  3. add the following line to you php.ini that usually resides in a dir above

    e.g. E:

    mpp\php\

    </p>
    
    	<p>extension=php_tidy.dll</p>
    
    	<p>

  4. Then you can issue php -m to check if the module tidy is loaded ok.

  5. READY! :-)

Tidy plugin installation on Linux

this is a bit tougher, and only explained for PHP4, as for PHP5 it only requires a

compile using the —with-tidy option. according to the PHP page

  1. Phase 1: we need libtidy

  2. </p>
    
    	<p>wget http://tidy.sourceforge.net/src/tidy_src.tgz</p>
    
    	<p>tar -zxvf tidy_src</p>
    
    	<p>cd tidy</p>
    
    	<p>sh build/gnuauto/setup.sh<br />
    ./configure —with-shared</p>
    
    	<p>make</p>
    
    	<p>make install</p>
    
    	<p>

    you should see something like

    Libraries have been installed in:
       /usr/local/lib<br />
    

  3. then we need to compile the actual PHP extension as follows

  4. <br />
    wget http://pecl.php.net/get/tidy-1.2.tgz<br />
    tar -zxvf tidy-1.2.tgz<br />
    cd tidy-1.2<br />
    phpize<br />
    ./configure<br />
    make<br />
    make install<br />
    

  5. then you should have a tidy.so in your extension directory, e.g.

    <br />
    ll /usr/local/lib/php/extensions/<br />
    

  6. then you need to edit your php.ini (find that by issuing php -i |grep ini and take the right path

  7. find the line extension_dir and make sure it reflects the correct directory

  8. add a line of code that says

    <br />
    extension=tidy.so<br />
    

    to the block than holds these extension= lines

  9. Then you can issue php -m to check if the module tidy is loaded ok.

  10. if yes, then we are READY! :-) just make sure you restart Apache that kept an old php instance

Useful pages and resources that helped me with this today:

Tidy Documentation

PHP tidy page

PECL tidy page

Another setup tutorial where I used parts of

Update Jun 27: I noticed these instructions execute perfectly on a 64bit RHE4 (RedHat 4) Dual-Opteron system – however tidy is not available in PHP ... not yet sure about the reason… any help would be appreciated

Average rating
(1 vote)

Similar entries