I'm trying to get the XML contents and organize it as objects to retreive them in json file.
XML structure:
<lorem date="2017-01-01">
<ipsum key="a">0001</ipsum>
<ipsum key="b">0002</ipsum>
<ipsum key="c">0003</ipsum>
<ipsum key="d">0004</ipsum>
</lorem>
and PHP
<?php
$URL = simplexml_load_file("http://www.example.com");
foreach($URL -> lorem -> ipsum as $item){
$arr = array($item["key"] => $item["value"]);
}
echo json_encode($arr);
?>
At the end i would like to get json returned with the following structure:
{
"a": "0001",
"b": "0002",
"c": "0003",
"d": "0004",
}
But i'm stuck on how to retrieve values between the ipsum tags. And also the code above doesn't work as expected.
(string)$iteminstead of$item["value"]