I need to extract two data from an XML file. I am using this script:
Canzone in onda:
<?php
$estrazioneAPI = new SimpleXMLElement('http://api.radionomy.com/currentsong.cfm?radiouid=0523cc62-e00c-485e-8e65-aea2aa37702a&apikey=b3ec3722-a1e6-44af-9d95-cb97ade2f4dc&callmeback=yes&type=xml&cover=yes&previous=yes.xml', NULL, TRUE);
if(false === $estrazioneAPI)
{
echo "test";
}
$canzoni = $estrazioneAPI->xpath("//tracks");
if(count($canzoni) > 0) {
foreach($canzoni as $track) {
$titolo = $track->track->title;
$artista = $track->track->artists;
if($titolo == '' AND $artista == ''){
echo "Nessuna canzone in onda";
}else if($titolo == '' AND $artista != ''){
echo "$artista - Titolo non riconosciuto";
}else if($titolo != '' AND $artista == ''){
echo "Artista non riconosciuto - $titolo";
}else{
echo $artista . " - " . $titolo;
}
}
}
?>
</marquee></i>
Going to the page where I put this script works correctly, the problem is that on another page I put this to update the data every 15 seconds:
<script>
$(document).observe('dom:loaded', function() {
new Ajax.PeriodicalUpdater('canzoneInOnda', '../api_webbo/canzone_in_onda.php', { frequency: 15 });
});
</script>
<div id="canzoneInOnda"></div>
Everything is OK except that this writing comes out from time to time:
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML
Then at the next update it returns to work normally... How could I solve?