$filename = null,$config = null,$encoding = null,$useIncludePath = false构造一个新的 tidy 对象。
filename如果提供了 $filename 参数,此函数还会读取该文件并使用该文件初始化对象,其作用类似于 tidy_parse_file()。
config$config 配置可以作为数组或字符串传递。如果传递的是字符串,则将其解释为配置文件的名称,否则将其解释为选项本身。
有关每个选项的说明,请访问 » http://api.html-tidy.org/#quick-reference。
encoding$encoding 参数设置输入/输出文档的编码。编码的可能值为:ascii、latin0、latin1、raw、utf8、iso2022、mac、win1252、ibm858、utf16、utf16le、utf16be、big5 和 shiftjis。
useIncludePath在 include_path 中搜索文件。
当构造函数失败(例如,无法打开文件)时抛出异常。
| 版本 | 描述 |
|---|---|
| 8.4.0 | 执行构造函数失败时现在会抛出异常,而不是静默创建不可用的对象。 |
| 8.0.0 |
$filename、$config、$encoding 和 $useIncludePath 现在可以为空。 |
示例 #1 tidy::__construct() 示例
<?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 <bt />
text</p>
</body></html>
HTML;
$tidy = new tidy();
$tidy->ParseString($html);
$tidy->cleanRepair();
if ($tidy->errorBuffer) {
echo "The following errors were detected:\n";
echo $tidy->errorBuffer;
}
?>以上示例将输出
The following errors were detected: line 8 column 14 - Error: <bt> is not recognized! line 8 column 14 - Warning: discarding unexpected <bt>