/Main_Page

::You must have ninja focus to complete your mission::NinjaFocus::

PHP HTML Tidy

Views:

<?php
/**
 * @package ninja
 * @copyright Kieran Whitbread 2009-2010
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 */

/**
 * A simple class to help work with PHP's HTML Tidy extesion
 *
 * @package ninja
 * @author Kieran Whitbread
 **/
class NinjaTidy
{
    public $config = array( 
            'clean' => true, 
            'drop-empty-paras' => false,
            'drop-proprietary-attributes' => true, 
            'fix-bad-comments' => true,
            'indent-spaces' => 0,
            'input-xml' => false,
            'numeric-entities' => false,
            'output-bom' => 0,
            'output-xhtml' => true, 
            'output-xml' => false,
            'quote-nbsp' => true,
            'show-body-only' => false,
            'tab-size' => 1,
            'word-2000' => true,
            'wrap' => false,
        );
    protected $html = null;
    protected $tidy = null;
    
    public function __construct($html = null)
    {
        $this->html = null;
        $this->tidy = new Tidy();
    }
    
    public function tidy($html = null)
    {
        if (is_null($html))
        {
            $html = $this->html;
        }
        $this->tidy->parseString($html, $this->config, 'utf8');
        $this->tidy->cleanRepair();
        return tidy_get_output($this->tidy);
    }
}

Main Menu

Personal tools

Toolbox