xml-json - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of xml-json.php

  1. <?php
  2.  
  3. $response = '<xml version="1.0">
  4.         <Response>
  5.                 <ResponseCode>00</ResponseCode>
  6.                 <ResponseDescription>Approved or Completed Successfully</ResponseDescription>
  7.                 <Items>1</Items>
  8.                 <Items>2</Items>
  9.                 <Items>3</Items>
  10.         </Response>
  11. </xml>';
  12.  
  13. $xml = simplexml_load_string(trim($response));
  14. $arr = json_decode(json_encode($xml), TRUE);
  15. $json = json_encode($arr, JSON_PRETTY_PRINT);
  16.  
  17. echo $json;
File Description
  • xml-json
  • PHP Code
  • 14 Dec-2018
  • 396 Bytes
You can Share it: