1--TEST-- 2libxml_set_external_entity_loader() basic test 3--SKIPIF-- 4<?php if (!extension_loaded('dom')) die('skip'); ?> 5--FILE-- 6<?php 7$xml = <<<XML 8<!DOCTYPE foo PUBLIC "-//FOO/BAR" "http://example.com/foobar"> 9<foo>bar</foo> 10XML; 11 12$dtd = <<<DTD 13<!ELEMENT foo (#PCDATA)> 14DTD; 15 16libxml_set_external_entity_loader( 17 function ($public, $system, $context) use($dtd){ 18 var_dump($public); 19 var_dump($system); 20 var_dump($context); 21 $f = fopen("php://temp", "r+"); 22 fwrite($f, $dtd); 23 rewind($f); 24 return $f; 25 } 26); 27 28$dd = new DOMDocument; 29$r = $dd->loadXML($xml); 30var_dump($dd->validate()); 31 32echo "Done.\n"; 33 34--EXPECT-- 35string(10) "-//FOO/BAR" 36string(25) "http://example.com/foobar" 37array(4) { 38 ["directory"]=> 39 NULL 40 ["intSubName"]=> 41 NULL 42 ["extSubURI"]=> 43 NULL 44 ["extSubSystem"]=> 45 NULL 46} 47bool(true) 48Done. 49