PHP SimpleXML to JSON Encode single element array -
i trying parse xml php single element json array.
this have:
$t = array(); $a=array("url"=>$test->channel->item->link); array_push($t,$a); echo json_encode($t);;
which gives me this:
[{"url":{"0":"http:www.example.com"}}]
but i looking this:
[{"url":"http:www.example.com"}]
it seems $test->channel->item->link
parses curly brackets {url}
but if echo $test->channel->item->link
, get: www.example.com
without curly brackets.
not sure if you're looking for, works :)
$xmlstr = '<?xml version=\'1.0\' standalone=\'yes\'?> <container> <channel> <item> <link>www.example.com</link> </item> </channel> </container>'; $test = new simplexmlelement($xmlstr); $t = array(); $a = array("url"=>$test->channel->item->link->__tostring()); array_push($t,$a); echo json_encode($t); // [{"url":"www.example.com"}]
Comments
Post a Comment