Hey guys so I have the following script which does seem to work as expected because the curl returns a blurb of text instead:
<?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;
}
$xml_str = download_page('http://api.npr.org/list?id=3002');
echo $xml_str; //SPITS OUTS A BLURB OF TEXT
$xml = new SimpleXMLElement(file_get_contents("test.xml"));
$items = $xml->xpath('*/item');
print_r($items); //RETURNS Array()
foreach($items as $item) {
echo "one time";
echo $item['title'], ': ', $item['description'], "
";
}
?>
I have no idea how to download the XML page into a normal XML format rather than this blurb of text.