DOMDocumentFragment->appendXML('php code here');
Posted: Sun Mar 21, 2010 2:55 pm
I'm trying to output html with DOM and everything is working fine but now I need to also add some php code in the document.
I read that using DOMDocumentFragment will do the job but it does nothing my case. For example:
<?php
$dom = new DOMDocument('1.0');
$body = $dom->createElement("body");
$dom->appendChild($body);
$php = $dom->createDocumentFragment();
$php->appendXML('<?php echo "good"; ?>');
$body->appendChild($php);
echo $dom->saveXML();
?>
When I launch this in my browser the page is just blank. In the source code you can see the php code (which isn't desired) but it doesn't execute.
Any help would be greatly appreciated.
I read that using DOMDocumentFragment will do the job but it does nothing my case. For example:
<?php
$dom = new DOMDocument('1.0');
$body = $dom->createElement("body");
$dom->appendChild($body);
$php = $dom->createDocumentFragment();
$php->appendXML('<?php echo "good"; ?>');
$body->appendChild($php);
echo $dom->saveXML();
?>
When I launch this in my browser the page is just blank. In the source code you can see the php code (which isn't desired) but it doesn't execute.
Any help would be greatly appreciated.