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();
<!doctype html> <html> <head> <title>PHP</title> <style> html, a { background-color: rgb(255 0 255 / 0.1); } a { color: purple; transition-duration: 1s; &:hover { background-color: rgb(0 0 0 / 0.1); color: black; text-decoration-color: transparent; } } </style> </head> <body> <a href="/php/">PHP</a> <script> function myfunction(myparameter) { const mytarget = myparameter.target; const mystyle = mytarget.style; mystyle.position = "absolute"; if(mystyle.left == "") { mystyle.left = "8px"; mystyle.top = "8px"; } mystyle.left = `${Math.random() * (window.innerWidth - mytarget.offsetWidth)}px`; mystyle.top = `${Math.random() * (window.innerHeight - mytarget.offsetHeight)}px`; } document.querySelector("a").addEventListener("mouseout", myfunction); </script> </body> </html>