Skip to content

Instantly share code, notes, and snippets.

@tuki0918
Created September 6, 2014 10:33
Show Gist options
  • Select an option

  • Save tuki0918/6d99b1d8f0a81f59b080 to your computer and use it in GitHub Desktop.

Select an option

Save tuki0918/6d99b1d8f0a81f59b080 to your computer and use it in GitHub Desktop.
php XML -> json -> Pretty
{
"information": {
"time": "1409999243"
},
"item": {
"a": "111",
"b": "222",
"c": "333"
}
}
<?php
$xml = '<?xml version="1.0" encoding="UTF-8"?>
<test>
<information>
<time>1409999243</time>
</information>
<item>
<a>111</a>
<b>222</b>
<c>333</c>
</item>
</test>';
$object = @simplexml_load_string($xml);
if ($object) {
$data = get_object_vars($object);
if (is_array($data)) {
echo '<pre>';
echo json_encode($data, JSON_PRETTY_PRINT);
echo '</pre>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment