我正在使用php扩展tidy-html来清理php输出。我知道tidy会删除无效的标签,而且甚至不能处理HTML5 doctype,但我正在使用的标签
奇怪的是,在此之前它并没有这样做。 我更改了tidy的配置,但它仍然无效。 现在我已经关闭了所有会影响标签的选项,但也没有帮助。
我的脚本相当冗长:
请注意,这比上面说的更加复杂(因此需要两个数组)。我只是删掉了不必要的代码。
<menu>
曾经出现在HTML规范中。 然而,它最终被更改为<ul>
。奇怪的是,在此之前它并没有这样做。 我更改了tidy的配置,但它仍然无效。 现在我已经关闭了所有会影响标签的选项,但也没有帮助。
我的脚本相当冗长:
$tidy_config = array(
'char-encoding' => 'utf8',
'output-encoding' => 'utf8',
'output-html' => true,
'numeric-entities' => false,
'ascii-chars' => false,
'doctype' => 'loose',
'clean' => false,
'bare' => false,
'fix-uri' => true,
'indent' => true,
'indent-spaces' => 2,
'tab-size' => 2,
'wrap-attributes' => true,
'wrap' => 0,
'indent-attributes' => true,
'join-classes' => false,
'join-styles' => false,
'fix-bad-comments' => true,
'fix-backslash' => true,
'replace-color' => false,
'wrap-asp' => false,
'wrap-jste' => false,
'wrap-php' => false,
'wrap-sections' => false,
'drop-proprietary-attributes' => false,
'hide-comments' => false,
'hide-endtags' => false,
'drop-empty-paras' => true,
'quote-ampersand' => true,
'quote-marks' => true,
'quote-nbsp' => true,
'vertical-space' => true,
'wrap-script-literals' => false,
'tidy-mark' => true,
'merge-divs' => false,
'repeated-attributes' => 'keep-last',
'break-before-br' => false
);
$tidy_config2 = array(
'tidy-mark' => false,
'vertical-space' => false,
'hide-comments' => true,
'indent-spaces' => 0,
'tab-size' => 1,
'wrap-attributes' => false,
'numeric-entities' => true,
'ascii-chars' => true,
'hide-endtags' => true,
'indent' => false
);
$tidy_config = array_merge($tidy_config, $tidy_config2);
$dtm = preg_match(self::doctypeMatch, $output, $dt);
$output = tidy_repair_string($output, $tidy_config, 'utf8');
// tidy screws up doctype --fixed
if($dtm)
$output = preg_replace(self::doctypeMatch, $dt[0], $output);
$output = preg_replace('!>[\n\r]+<!', '><', $output);
unset($tidy_config);
return $output;
请注意,这比上面说的更加复杂(因此需要两个数组)。我只是删掉了不必要的代码。