<!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>Changes the default external entity loader</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.libxml-get-last-error.html">libxml_get_last_error</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.libxml-set-streams-context.html">libxml_set_streams_context</a></div> <div class="up"><a href="ref.libxml.html">libxml Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.libxml-set-external-entity-loader" class="refentry"> <div class="refnamediv"> <h1 class="refname">libxml_set_external_entity_loader</h1> <p class="verinfo">(PHP 5 >= 5.4.0)</p><p class="refpurpose"><span class="refname">libxml_set_external_entity_loader</span> — <span class="dc-title">Changes the default external entity loader</span></p> </div> <div class="refsect1 description" id="refsect1-function.libxml-set-external-entity-loader-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type"><span class="type void">void</span></span> <span class="methodname"><strong>libxml_set_external_entity_loader</strong></span> ( <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$resolver_function</code></span> )</div> <p class="para rdfs-comment"> Changes the default external entity loader. </p> </div> <div class="refsect1 parameters" id="refsect1-function.libxml-set-external-entity-loader-parameters"> <h3 class="title">Parameters</h3> <dl> <dt> <span class="term"><em><code class="parameter">resolver_function</code></em></span> <dd> <p class="para"> A <span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> that takes three arguments. Two strings, a public id and system id, and a context (an array with four keys) as the third argument. This callback should return a resource, a string from which a resource can be opened, or <strong><code>NULL</code></strong>. </p> </dd> </dt> </dl> </div> <div class="refsect1 returnvalues" id="refsect1-function.libxml-set-external-entity-loader-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> No value is returned. </p> </div> <div class="refsect1 examples" id="refsect1-function.libxml-set-external-entity-loader-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-5440"> <p><strong>Example #1 <span class="function"><strong>libxml_set_external_entity_loader()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$xml </span><span style="color: #007700">= <<<XML<br /></span><span style="color: #DD0000"><!DOCTYPE foo PUBLIC "-//FOO/BAR" "http://example.com/foobar"><br /><foo>bar</foo><br /></span><span style="color: #007700">XML;<br /><br /></span><span style="color: #0000BB">$dtd </span><span style="color: #007700">= <<<DTD<br /></span><span style="color: #DD0000"><!ELEMENT foo (#PCDATA)><br /></span><span style="color: #007700">DTD;<br /><br /></span><span style="color: #0000BB">libxml_set_external_entity_loader</span><span style="color: #007700">(<br /> function (</span><span style="color: #0000BB">$public</span><span style="color: #007700">, </span><span style="color: #0000BB">$system</span><span style="color: #007700">, </span><span style="color: #0000BB">$context</span><span style="color: #007700">) use(</span><span style="color: #0000BB">$dtd</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$public</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$system</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$context</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$f </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"php://temp"</span><span style="color: #007700">, </span><span style="color: #DD0000">"r+"</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$f</span><span style="color: #007700">, </span><span style="color: #0000BB">$dtd</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">rewind</span><span style="color: #007700">(</span><span style="color: #0000BB">$f</span><span style="color: #007700">);<br /> return </span><span style="color: #0000BB">$f</span><span style="color: #007700">;<br /> }<br />);<br /><br /></span><span style="color: #0000BB">$dd </span><span style="color: #007700">= new </span><span style="color: #0000BB">DOMDocument</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$r </span><span style="color: #007700">= </span><span style="color: #0000BB">$dd</span><span style="color: #007700">-></span><span style="color: #0000BB">loadXML</span><span style="color: #007700">(</span><span style="color: #0000BB">$xml</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$dd</span><span style="color: #007700">-></span><span style="color: #0000BB">validate</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> string(10) "-//FOO/BAR" string(25) "http://example.com/foobar" array(4) { ["directory"] => NULL ["intSubName"] => NULL ["extSubURI"] => NULL ["extSubSystem"] => NULL } bool(true) </pre></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-function.libxml-set-external-entity-loader-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.libxml-disable-entity-loader.html" class="function" rel="rdfs-seeAlso">libxml_disable_entity_loader()</a> - Disable the ability to load external entities</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="function.libxml-get-last-error.html">libxml_get_last_error</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.libxml-set-streams-context.html">libxml_set_streams_context</a></div> <div class="up"><a href="ref.libxml.html">libxml Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>