<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Load HTML from a string</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="domdocument.load.html">DOMDocument::load</a></div> <div class="next" style="text-align: right; float: right;"><a href="domdocument.loadhtmlfile.html">DOMDocument::loadHTMLFile</a></div> <div class="up"><a href="class.domdocument.html">DOMDocument</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="domdocument.loadhtml" class="refentry"> <div class="refnamediv"> <h1 class="refname">DOMDocument::loadHTML</h1> <p class="verinfo">(PHP 5)</p><p class="refpurpose"><span class="refname">DOMDocument::loadHTML</span> — <span class="dc-title"> Load HTML from a string </span></p> </div> <div class="refsect1 description" id="refsect1-domdocument.loadhtml-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">bool</span> <span class="methodname"><strong>DOMDocument::loadHTML</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$source</code></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$options</code><span class="initializer"> = 0</span></span> ] )</div> <p class="para rdfs-comment"> The function parses the HTML contained in the string <em><code class="parameter">source</code></em>. Unlike loading XML, HTML does not have to be well-formed to load. This function may also be called statically to load and create a <a href="class.domdocument.html" class="classname">DOMDocument</a> object. The static invocation may be used when no <a href="class.domdocument.html" class="classname">DOMDocument</a> properties need to be set prior to loading. </p> </div> <div class="refsect1 parameters" id="refsect1-domdocument.loadhtml-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">source</code></em></span> <dd> <p class="para"> The HTML string. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">options</code></em></span> <dd> <p class="para"> Since PHP 5.4.0 and Libxml 2.6.0, you may also use the <em><code class="parameter">options</code></em> parameter to specify <a href="libxml.constants.html" class="link">additional Libxml parameters</a>. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-domdocument.loadhtml-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <strong><code>TRUE</code></strong> on success or <strong><code>FALSE</code></strong> on failure. If called statically, returns a <a href="class.domdocument.html" class="classname">DOMDocument</a> or <strong><code>FALSE</code></strong> on failure. </p> </div> <div class="refsect1 errors" id="refsect1-domdocument.loadhtml-errors"> <h3 class="title">Errors/Exceptions</h3> <p class="para"> If an empty string is passed as the <em><code class="parameter">source</code></em>, a warning will be generated. This warning is not generated by libxml and cannot be handled using libxml's error handling functions. </p> <p class="para">This method <em class="emphasis">may</em> be called statically, but will issue an <strong><code>E_STRICT</code></strong> error.</p> <p class="para">While malformed HTML should load successfully, this function may generate <strong><code>E_WARNING</code></strong> errors when it encounters bad markup. <a href="function.libxml-use-internal-errors.html" class="link">libxml's error handling functions</a> may be used to handle these errors.</p> </div> <div class="refsect1 examples" id="refsect1-domdocument.loadhtml-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-5407"> <p><strong>Example #1 Creating a Document</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?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">-></span><span style="color: #0000BB">loadHTML</span><span style="color: #007700">(</span><span style="color: #DD0000">"<html><body>Test<br></body></html>"</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$doc</span><span style="color: #007700">-></span><span style="color: #0000BB">saveHTML</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 changelog" id="refsect1-domdocument.loadhtml-changelog"> <h3 class="title">Changelog</h3> <p class="para"> <table class="doctable informaltable"> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>5.4.0</td> <td> Added <em><code class="parameter">options</code></em> parameter. </td> </tr> </tbody> </table> </p> </div> <div class="refsect1 seealso" id="refsect1-domdocument.loadhtml-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="methodname"><a href="domdocument.loadhtmlfile.html" class="methodname" rel="rdfs-seeAlso">DOMDocument::loadHTMLFile()</a> - Load HTML from a file</span></li> <li class="member"> <span class="methodname"><a href="domdocument.savehtml.html" class="methodname" rel="rdfs-seeAlso">DOMDocument::saveHTML()</a> - Dumps the internal document into a string using HTML formatting</span></li> <li class="member"> <span class="methodname"><a href="domdocument.savehtmlfile.html" class="methodname" rel="rdfs-seeAlso">DOMDocument::saveHTMLFile()</a> - Dumps the internal document into a file using HTML formatting</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="domdocument.load.html">DOMDocument::load</a></div> <div class="next" style="text-align: right; float: right;"><a href="domdocument.loadhtmlfile.html">DOMDocument::loadHTMLFile</a></div> <div class="up"><a href="class.domdocument.html">DOMDocument</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>