hello, I am invoking PHP curl method on a server and the response is XML type. Curl is saving the output ( after removing the tags ) in a scalar type variable. Is there a way to store it in a object/hash/array. So that its easy to parse.\
Thanks
hello, I am invoking PHP curl method on a server and the response is XML type. Curl is saving the output ( after removing the tags ) in a scalar type variable. Is there a way to store it in a object/hash/array. So that its easy to parse.\
Thanks
no, CURL does not have anything with parsing XML, it does not know anything about the content returned. it serves as a proxy to get content. it's up to you what to do with it.
use JSON if possible (and json_decode) - it's easier to work with, if not possible, use any XML library for parsin such as DOMXML: http://php.net/domxml
<?php
function download_page($path){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$path);
curl_setopt($ch, CURLOPT_FAILONERROR,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$retValue = curl_exec($ch);
curl_close($ch);
return $retValue;
}
$sXML = download_page('http://alanstorm.com/atom');
$oXML = new SimpleXMLElement($sXML);
foreach($oXML->entry as $oEntry){
echo $oEntry->title . "\n";
}