Ciao, sto usando questo script funzionante per estrarre il testo da un tag xml:
Codice PHP:
<?php
$xml = '
<tracks>
<radioname>Ixtreme Radio</radioname>
<rank>0</rank>
<isradionomy>1</isradionomy>
<radurl>http://www.radionomy.com/ixtremeradio</radurl>
<track>
<uniqueid>4014324288</uniqueid>
<title>Mask Off</title>
<artists>Future</artists>
<starttime>2017-06-28 23:25:02.303</starttime>
<playduration>201803</playduration>
<current>1</current>
<cover>
http://i3.radionomy.com/tracks/232/04aebbff-c2d9-4d47-a570-44b5f55edd3d?radiouid=80b5e81c-c769-478a-aee7-fbe149aacfe3
</cover>
<callmeback>62922</callmeback>
</track>
</tracks>';
$xmlcont = new SimpleXMLElement($xml);
echo "Canzone in onda:" . $xmlcont->track->title . " di " . $xmlcont->track->artists;
?>
Lo script restituisce correttamente:
Canzone in onda:Mask Off di Future
Purtroppo però a me serve che invece di leggere il file xml dalla variabile $xml
lo legga da questo link: http://api.radionomy.com/currentsong...evious=yes.xml
Ho provato:
Codice PHP:
<?php
$xml = simplexml_load_file("http://api.radionomy.com/currentsong.cfm?radiouid=80b5e81c-c769-478a-aee7-fbe149aacfe3&apikey=cf415862-c0ac-4085-bc03-be80a26f9063&callmeback=yes&type=xml&cover=yes&previous=yes.xml");
$xmlcont = new SimpleXMLElement($xml);
echo "Canzone in onda:" . $xmlcont->track->title . " di " . $xmlcont->track->artists;
?>
Ma restituisce questo errore:
Codice:
Warning: SimpleXMLElement::__construct(): Entity: line 9: parser error : Start tag expected, '<' not found in C:\xampp2\htdocs\2017\call_api.php on line 4
Warning: SimpleXMLElement::__construct(): in C:\xampp2\htdocs\2017\call_api.php on line 4
Warning: SimpleXMLElement::__construct(): ^ in C:\xampp2\htdocs\2017\call_api.php on line 4
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in C:\xampp2\htdocs\2017\call_api.php:4 Stack trace: #0 C:\xampp2\htdocs\2017\call_api.php(4): SimpleXMLElement->__construct('\n \t\n ...') #1 {main} thrown in C:\xampp2\htdocs\2017\call_api.php on line 4