PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I've got a problem:
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
error_reporting(E_ALL); // so you will see the errors
// not valid XML without double quotes
// also when tested it standalone caused problems, so i've removed
$xmlstr = <<< XML
<?xml version="1.0" encoding="UTF-8"?>
<root>
<element>Element1</element>
<element>Element2</element>
</root>
XML;
$sxe = new SimpleXMLElement($xmlstr);
// use single quotes for all strings without escape characters or embedded variables
$sxe->addChild('test', 'Test!!!'); // in my version of php 5.1.2 this function does not exist.
echo nl2br(htmlentities($sxe->asXML()));