Skip to content

Instantly share code, notes, and snippets.

@daniel-v
Created May 5, 2016 12:59
Show Gist options
  • Save daniel-v/008e16b98e0b9484ff17f94c175a7f6a to your computer and use it in GitHub Desktop.
Save daniel-v/008e16b98e0b9484ff17f94c175a7f6a to your computer and use it in GitHub Desktop.
SimpleXML encode/decode ref sample
<?php
$xml = <<<EOF
<?xml version="1.0" encoding="utf-8"?>
<doc>
<test>
&lt;You shall do pass&gt;
</test>
</doc>
EOF;
$XMLElement = simplexml_load_string($xml);
// First test - can I get the same output?
echo $XMLElement->asXML();
// Second test - what do I get when I encode?
echo (string)$XMLElement->test;
// Third test - can I get unencoded contents of test?
echo $XMLElement->test->asXML();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment