tidy::__construct()
(PHP 5, PHP 7, PECL tidy >= 0.5.2)
构造一个新的tidy对象
说明
public tidy::__construct([string $filename[,mixed $config[,string $encoding[,bool $use_include_path]]]])
参数
- $filename:如果给定了$filename参数,此函数还将读取该文件并用该文件初始化对象,就像
tidy_parse_file()一样。 - $config:配置$config可以作为数组或字符串传递。如果传递字符串,则将其解释为配置文件的名称,否则,将其解释为选项本身。
- $encoding设置输入/输出文档的编码。可能的编码值是:ascii,latin0,latin1,raw,utf8,iso2022,mac,win1252,ibm858,utf16,utf16le,utf16be,big5, shiftjis.
- $use_include_path:在包含路径中搜索文件
返回值
返回新的tidy实例
范例
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>
参见
- tidy::parseFile() 分析文件或URI中的标记
- tidy::parseString() 分析存储在字符串中的文档
