<?php

$tidy = new tidy();
$str = <<<EOF
<p>Isto é um texto em Português<br>
para testes.</p>
EOF;
$tidy->parseString($str, array('output-xhtml' => 1), 'latin1');
$tidy->cleanRepair();
$tidy->diagnose();
var_dump(tidy_warning_count($tidy) > 0);
var_dump(strlen($tidy->errorBuffer) > 50);
echo $tidy;
Example #2
0
 /**
  * @param CM_Dom_NodeList $page
  * @param bool            $warnings
  */
 public static function assertTidy(CM_Dom_NodeList $page, $warnings = true)
 {
     if (!extension_loaded('tidy')) {
         self::markTestSkipped('The tidy extension is not available.');
     }
     $html = $page->getHtml();
     $tidy = new tidy();
     $tidyConfig = array('show-errors' => 1, 'show-warnings' => $warnings);
     $tidy->parseString($html, $tidyConfig, 'UTF8');
     //$tidy->cleanRepair();
     $tidy->diagnose();
     $lines = array_reverse(explode("\n", $tidy->errorBuffer));
     $content = '';
     foreach ($lines as $line) {
         if (empty($line) || $line == 'No warnings or errors were found.' || strpos($line, 'Info:') === 0 || strpos($line, 'errors were found!') > 0 || strpos($line, 'proprietary attribute') != false) {
             // ignore
         } else {
             $content .= $line . PHP_EOL;
         }
     }
     self::assertEmpty($content, $content);
 }
Example #3
0
function do_tidy($raw_html, $tag_for_error = "")
{
    $html = "<!DOCTYPE html PUBLIC" . " '-//W3C//DTD XHTML 1.0 Transitional//EN'" . " 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'" . ">" . "<html xmlns='http://www.w3.org/1999/xhtml'>" . "<head>" . "<meta http-equiv='Content-Type'" . " content='text/html; charset=utf-8' />" . "<title></title>" . "</head>" . "<body>";
    $html .= $raw_html;
    $html .= "\n</body></html>\n";
    $config = array();
    $config['indent'] = 1;
    $config['indent-spaces'] = 4;
    $config['indent-attributes'] = 1;
    $config['wrap'] = 120;
    $config['gnu-emacs'] = 1;
    $config['literal-attributes'] = 1;
    $config['output-xhtml'] = 1;
    $config['quote-nbsp'] = 1;
    $config['show-errors'] = 10;
    $config['vertical-space'] = 1;
    // $config['TidyCharEncoding'] = "utf8";
    $config['show-body-only'] = 1;
    $config['force-output'] = 1;
    $config['quiet'] = 1;
    $tidy = new tidy();
    $tidy->parseString($html, $config, 'utf8');
    $tidy->cleanRepair();
    $tidy->diagnose();
    if ($tidy->errorBuffer) {
        global $tidy_errs;
        if (!isset($tidy_errs)) {
            $tidy_errs = "";
        }
        if ($tag_for_error) {
            $tidy_errs .= sprintf("<p>errors in %s</p>\n", h($tag_for_error));
        }
        $tidy_errs .= "<pre>\n";
        $tidy_errs .= htmlentities($tidy->errorBuffer, ENT_QUOTES, 'UTF-8');
        $tidy_errs .= "</pre>\n";
    }
    return trim($tidy);
}