PHP: Issue extracting information from XML to create JSON

TonyMontac

New Member
I need to extract some data from a XML fetched online and to create a JSON from the result.Here is a simplified version of the issue I encounter:\[code\]$XML=simplexml_load_file("http://somewhere.on.the.net/my.xml");$result = array();$tmpp = $XML->S->S["time"];echo $tmpp.'<br/>';;$result['DATE'] = $tmpp;echo json_encode($result);\[/code\]I get:\[code\]2012-05-29{"DATE":{"0":"2012-05-29"}}\[/code\]and I want:\[code\]{"DATE":"2012-05-29"}\[/code\]How can I achieve this? Thanks.UpdateHere is the structure of the XML:\[code\]<g:e><S> <S time="2012-05-29"> <S info1="a" info2="b"/> <S info1="d" info2="m"/> <S info1="q" info2="l"/> ... </S> <S time="2011-04-09"> <S info1="a" info2="z"/> ... </S> </S> ...</S></g:e>\[/code\]
 
Back
Top