
json_encode child element attributes
By:
JPeterson on
Apr 14th, 2012 | syntax:
PHP | size: 0.17 KB | hits: 37 | expires: Never
<?php
header("Content-Type: text/plain");
$xml = <<<XML
<a>
<b a="value">text</b>
</a>
XML;
print_r(json_encode((array)simplexml_load_string($xml)));
// {"b":"text"}