Created
September 6, 2014 10:33
-
-
Save tuki0918/6d99b1d8f0a81f59b080 to your computer and use it in GitHub Desktop.
php XML -> json -> Pretty
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "information": { | |
| "time": "1409999243" | |
| }, | |
| "item": { | |
| "a": "111", | |
| "b": "222", | |
| "c": "333" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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