- simplexml_load_string: documentation ( source)
- libxml_disable_entity_loader: documentation ( source)
<?php
/**
* @link http://stackoverflow.com/a/29864193/367456
*/
$buffer = <<<XML
<?xml version="1.0"?>
<!--
====================================
xhtml-lat1.ent
====================================
-->
<!-- Portions (C) International Organization for Standardization 1986
Permission to copy in any form is granted for use with
conforming SGML systems and applications as defined in
ISO 8879, provided this notice is included in all copies.
-->
<!-- Character entity set. Typical invocation:
<!ENTITY % HTMLlat1 PUBLIC
"-//W3C//ENTITIES Latin 1 for XHTML//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent">
%HTMLlat1;
-->
<!ENTITY nbsp " "> <!-- no-break space = non-breaking space,
U+00A0 ISOnum --><foo> </foo>
XML;
libxml_disable_entity_loader(false);
$xml = simplexml_load_string($buffer);
$xml->asXML('php://output');
$xml = simplexml_load_string($buffer, 'SimpleXMLElement', LIBXML_NOENT);
$xml->asXML('php://output');