DOMDocument::loadHTMLFile
(PHP 5, PHP 7, PHP 8)
DOMDocument::loadHTMLFile — Load HTML from a file
說明
The function parses the HTML document in the file named
filename
. Unlike loading XML, HTML does not have
to be well-formed to load.
參數
-
filename
-
The path to the HTML file.
-
options
-
Since Libxml 2.6.0, you may also use the
options
parameter to specify additional Libxml parameters.
返回值
成功時返回 true
, 或者在失敗時返回 false
。 If called statically, returns a
DOMDocument 或者在失敗時返回 false
.
錯誤/異常
If an empty string is passed as the filename
or an empty file is named, a warning will be generated. This warning
is not generated by libxml and cannot be handled using libxml's error handling
functions.
在 PHP 8.0.0 之前可以靜態呼叫此方法,但會發出
E_DEPRECATED
錯誤。自 PHP 8.0.0 起,靜態呼叫此方法會拋出 Error 異常
儘管非正確格式化的 HTML 仍應該被成功調入,但此函式會在遇到錯誤標記時產生 E_WARNING
錯誤。libxml 錯誤處理函式可以用來處理這類錯誤。
範例
示例 #1 Creating a Document
<?php
$doc = new DOMDocument();
$doc->loadHTMLFile("filename.html");
echo $doc->saveHTML();
?>
參見
- DOMDocument::loadHTML() - Load HTML from a string
- DOMDocument::saveHTML() - Dumps the internal document into a string using HTML formatting
- DOMDocument::saveHTMLFile() - Dumps the internal document into a file using HTML formatting