(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.
filenameThe path to the HTML file.
options
Since Libxml 2.6.0, you may also use the
options parameter to specify additional Libxml parameters.
成功時(shí)返回 true, 或者在失敗時(shí)返回 false。 If called statically, returns a
DOMDocument 或者在失敗時(shí)返回 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 之前可以靜態(tài)調(diào)用此方法,但會(huì)發(fā)出
E_DEPRECATED 錯(cuò)誤。自 PHP 8.0.0 起,靜態(tài)調(diào)用此方法會(huì)拋出 Error 異常
盡管非正確格式化的 HTML 仍應(yīng)該被成功調(diào)入,但此函數(shù)會(huì)在遇到錯(cuò)誤標(biāo)記時(shí)產(chǎn)生 E_WARNING 錯(cuò)誤。libxml 錯(cuò)誤處理函數(shù)可以用來(lái)處理這類(lèi)錯(cuò)誤。
示例 #1 Creating a Document
<?php
$doc = new DOMDocument();
$doc->loadHTMLFile("filename.html");
echo $doc->saveHTML();
?>