<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.domdocument.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'domdocument.loadhtmlfile.php',
    1 => 'DOMDocument::loadHTMLFile',
    2 => 'Load HTML from a file',
  ),
  'up' => 
  array (
    0 => 'class.domdocument.php',
    1 => 'DOMDocument',
  ),
  'prev' => 
  array (
    0 => 'domdocument.loadhtml.php',
    1 => 'DOMDocument::loadHTML',
  ),
  'next' => 
  array (
    0 => 'domdocument.loadxml.php',
    1 => 'DOMDocument::loadXML',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/dom/domdocument/loadhtmlfile.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="domdocument.loadhtmlfile" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">DOMDocument::loadHTMLFile</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">DOMDocument::loadHTMLFile</span> &mdash; <span class="dc-title">
   Load HTML from a file
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-domdocument.loadhtmlfile-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>DOMDocument::loadHTMLFile</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$filename</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$options</code><span class="initializer"> = 0</span></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   The function parses the HTML document in the file named
   <code class="parameter">filename</code>. Unlike loading XML, HTML does not have
   to be well-formed to load.
  </p>
  <div class="warning"><strong class="warning">Warning</strong>
 <p class="simpara">
  Use <span class="classname"><a href="class.dom-htmldocument.php" class="classname">Dom\HTMLDocument</a></span> to parse and process modern HTML
  instead of <span class="classname"><a href="class.domdocument.php" class="classname">DOMDocument</a></span>.
 </p>
 <p class="simpara">
  This function parses the input using an HTML 4 parser. The parsing rules
  of HTML 5, which is what modern web browsers use, are different. Depending
  on the input this might result in a different DOM structure. Therefore
  this function cannot be safely used for sanitizing HTML.
 </p>
 <p class="simpara">
  The behavior when parsing HTML can depend on the version of
  <code class="literal">libxml</code> that is being used, particularly with regards to
  edge conditions and error handling.
  For parsing that conforms to the HTML5 specification,
  use <span class="methodname"><a href="dom-htmldocument.createfromstring.php" class="methodname">Dom\HTMLDocument::createFromString()</a></span> or
  <span class="methodname"><a href="dom-htmldocument.createfromfile.php" class="methodname">Dom\HTMLDocument::createFromFile()</a></span>, added in PHP 8.4.
 </p>
 <p class="simpara">
  As an example, some HTML elements will implicitly close a parent element
  when encountered. The rules for automatically closing parent elements
  differ between HTML 4 and HTML 5 and thus the resulting DOM structure that
  <span class="classname"><a href="class.domdocument.php" class="classname">DOMDocument</a></span> sees might be different from the DOM
  structure a web browser sees, possibly allowing an attacker to break the
  resulting HTML.
 </p>
</div>
 </div>

 <div class="refsect1 parameters" id="refsect1-domdocument.loadhtmlfile-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">filename</code></dt>
     <dd>
      <p class="para">
       The path to the HTML file.
      </p>
     </dd>
    
    
     <dt><code class="parameter">options</code></dt>
     <dd>
      <p class="para">
  <a href="language.operators.bitwise.php" class="link">Bitwise <code class="literal">OR</code></a>
  of the <a href="libxml.constants.php" class="link">libxml option constants</a>.
</p>
     </dd>
    
   </dl>
  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-domdocument.loadhtmlfile-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> on success or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on failure.
  </p>
 </div>

 <div class="refsect1 errors" id="refsect1-domdocument.loadhtmlfile-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <p class="para">
   If an empty string is passed as the <code class="parameter">filename</code>
   or an empty file is named, a warning will be generated. This warning
   is not generated by libxml and cannot be handled using <a href="function.libxml-use-internal-errors.php" class="link">libxml&#039;s error handling
   functions</a>.
  </p>
  <p class="para">While malformed HTML should load successfully, this function may generate <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> errors when it encounters bad markup. <a href="function.libxml-use-internal-errors.php" class="link">libxml&#039;s error handling functions</a> may be used to handle these errors.</p>
 </div>


 <div class="refsect1 changelog" id="refsect1-domdocument.loadhtmlfile-changelog">
  <h3 class="title">Changelog</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.3.0</td>
      <td>
       This function now has a tentative <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> return type.
      </td>
     </tr>

     <tr>
      <td>8.0.0</td>
      <td>
       Calling this function statically will
       now throw an <span class="classname"><a href="class.error.php" class="classname">Error</a></span>.
       Previously, an <strong><code><a href="errorfunc.constants.php#constant.e-deprecated">E_DEPRECATED</a></code></strong> was raised.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-domdocument.loadhtmlfile-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 Creating a Document</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$doc </span><span style="color: #007700">= new </span><span style="color: #0000BB">DOMDocument</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$doc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">loadHTMLFile</span><span style="color: #007700">(</span><span style="color: #DD0000">"filename.html"</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$doc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">saveHTML</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-domdocument.loadhtmlfile-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="methodname"><a href="domdocument.loadhtml.php" class="methodname" rel="rdfs-seeAlso">DOMDocument::loadHTML()</a> - Load HTML from a string</span></li>
    <li><span class="methodname"><a href="domdocument.savehtml.php" class="methodname" rel="rdfs-seeAlso">DOMDocument::saveHTML()</a> - Dumps the internal document into a string using HTML formatting</span></li>
    <li><span class="methodname"><a href="domdocument.savehtmlfile.php" class="methodname" rel="rdfs-seeAlso">DOMDocument::saveHTMLFile()</a> - Dumps the internal document into a file using HTML formatting</span></li>
   </ul>
  </p>
 </div>

</div><?php manual_footer($setup); ?>