libxml_set_external_entity_loader
Description
The libxml_set_external_entity_loader of libxml for PHP changes the default external entity loader.
Syntax
libxml_set_external_entity_loader( ?callable $resolver_function ): bool
Parameters
resolver_function
A callable with the following signature:
resolver( ?string $public_id, string $system_id, array $context ): resource|string|null
public_id
The public ID.
system_id
The system ID.
context
An array with the four elements "directory", "intSubName", "extSubURI" and "extSubSystem".
This callable should return a resource, a string from which a resource can be opened. If null is returned, the entity reference resolution will fail.
Return
Returns true on success or false on failure.
Examples
1 · resolver_function
<? function resolver($public_id, $system_id, $context) { return "mystring"; } $resolver_function = "resolver"; $return = libxml_set_external_entity_loader($resolver_function); var_export($return); ?>
true
2 · DOMDocument
<? function resolver($public_id, $system_id, $context) { var_dump($public_id, $system_id, $context); return "mystring"; } $resolver_function = "resolver"; libxml_set_external_entity_loader($resolver_function); $source = <<<XML <!DOCTYPE mytopelement PUBLIC "myregistration//myorganization//mytype mylabel mydefinition//mylanguage" "https://mydomain.com/mypath"> <my-element></my-element> XML; $dom = new DOMDocument; $dom->loadXML($source); $dom->validate(); ?>
string(71) "myregistration//myorganization//mytype mylabel mydefinition//mylanguage" string(27) "https://mydomain.com/mypath" array(4) { ["directory"]=> NULL ["intSubName"]=> NULL ["extSubURI"]=> NULL ["extSubSystem"]=> NULL }