2024 年 PHP 日本研討會

tidy::parseFile

tidy_parse_file

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

tidy::parseFile -- tidy_parse_file解析檔案或 URI 中的標記

說明

物件導向風格

public tidy::parseFile(
    字串 $filename,
    陣列 (array)|字串 (string)|空值 (null) $config = null,
    ?字串 (string) $encoding = null,
    布林值 (bool) $useIncludePath = false
): 布林值 (bool)

程序式風格

tidy_parse_file(
    字串 $filename,
    陣列 (array)|字串 (string)|空值 (null) $config = null,
    ?字串 (string) $encoding = null,
    布林值 (bool) $useIncludePath = false
): tidy|false

解析指定的檔案。

參數

filename (檔名)

如果提供了 filename 參數,這個函式也會讀取該檔案並用檔案內容初始化物件,作用類似 tidy_parse_file()

config (設定)

config 設定可以以陣列或字串形式傳遞。如果是字串,則會被解讀為設定檔的名稱,否則會被解讀為選項本身。

關於每個選項的說明,請參閱 » http://api.html-tidy.org/#quick-reference

encoding (編碼)

encoding 參數設定輸入/輸出文件的編碼。可能的編碼值有: asciilatin0latin1rawutf8iso2022macwin1252ibm858utf16utf16leutf16bebig5shiftjis

useIncludePath (使用 include 路徑)

include_path 中搜尋檔案。

回傳值

tidy::parseFile() 成功時回傳 truetidy_parse_file() 成功時回傳一個新的 tidy 實例。方法和函式在失敗時都會回傳 false

更新日誌

版本 說明
8.0.0 configencoding 現在可以為 null。

範例

範例 #1 tidy::parseFile() 範例

<?php
$tidy
= new tidy();
$tidy->parseFile('file.html');

$tidy->cleanRepair();

if(!empty(
$tidy->errorBuffer)) {
echo
"發生以下錯誤或警告:\n";
echo
$tidy->errorBuffer;
}
?>

另請參閱

新增筆記

使用者貢獻的筆記

此頁面沒有使用者貢獻的筆記。
To Top