PHP code example of extphp / xml-to-json
1. Go to this page and download the library: Download extphp/xml-to-json library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
extphp / xml-to-json example snippets
use ExtPHP\XmlToJson\XmlToJsonConverter;
$string = '<node attr1="value1" attr2="value2"><child>child value</child></node>';
$xml = simplexml_load_string($string);
$converter = new XmlToJsonConverter($xml);
$converter->toArray(); // convert xml to array
$converter->toJson(); // convert xml to json
use ExtPHP\XmlToJson\JsonableXML;
$xml = new JsonableXML('<node attr1="value1" attr2="value2"><child>child value</child></node>');
json_encode($xml); // convert xml to json
// These methods are also available directly on the xml object.
$xml->toArray(); // convert xml to array
$xml->toJson(); // convert xml to json