$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 現在可為 null。 |
範例 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>