ConFoo 2025

tidy_get_output

(PHP 5, PHP 7, PHP 8, PECL tidy >= 0.5.2)

tidy_get_outputReturn a string representing the parsed tidy markup

说明

tidy_get_output(tidy $tidy): string

Gets a string with the repaired html.

参数

tidy

The Tidy 对象。

返回值

Returns the parsed tidy markup.

示例

示例 #1 tidy_get_output() example

<?php

$html
= '<p>paragraph</i>';
$tidy = tidy_parse_string($html);

$tidy->cleanRepair();

echo
tidy_get_output($tidy);
?>

以上示例会输出:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title></title>
</head>
<body>
<p>paragraph</p>
</body>
</html>

添加备注

用户贡献的备注 1 note

up
1
jon+php_net at phpsitesolutions dot com
15 years ago
If you don't feel like going procedural to get the HTML output, you can simple use this alternative:

<?php

$html
= <<<HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><title>title</title></head>
<body>
<p>paragraph <br />
text</p>
</body></html>

HTML;

$tidy = new tidy;
$tidy->parseString($html);

$tidy->cleanRepair();
echo
$tidy->html()->value;

?>

You can even more simply access the HTML output via this:

<?php

echo $tidy->value;

?>
To Top