Reputation: 677
$song = "The Buzzcocks - Orgasm Addict";
$songeach = explode("-", $song);
$artist = trim($songeach[0]);
$song = trim($songeach[1]);
echo $artist;
//echos 'The Buzzcocks'
echo $song;
//echos 'Orgasm Addict'
$lyricxml1 = simplexml_load_file('http://api.chartlyrics.com/apiv1.asmx/SearchLyric?artist='.$artist.'&song='.$song.'');
$lyricchecksum2 = $lyricxml1->SearchLyricResult[0]->LyricChecksum;
$lyricid = $lyricxml1->SearchLyricResult[0]->LyricId;
echo $lyricchecksum2;
//echos 'c58a88a5cd5550b2793a408d17193af6'
echo $lyricid;
//echos '5497'
All good and proper so far.
But then once I get here
$lyricxml2 = simplexml_load_file('http://api.chartlyrics.com/apiv1.asmx/GetLyric?lyricId='.$lyricid.'&lyricCheckSum='.$lyricchecksum2.'');
print_r($lyricxml2);
I receive this error:
E_WARNING : type 2 -- simplexml_load_file(http://api.chartlyrics.com/apiv1.asmx/GetLyric?lyricId=5497&lyricCheckSum=c58a88a5cd5550b2793a408d17193af6): failed to open stream: HTTP request failed! -- at line 15
E_WARNING : type 2 -- simplexml_load_file(): I/O warning : failed to load external entity "http://api.chartlyrics.com/apiv1.asmx/GetLyric?lyricId=5497&lyricCheckSum=c58a88a5cd5550b2793a408d17193af6" -- at line 15
Even though the url/xml file is proper (works in browser manually) http://api.chartlyrics.com/apiv1.asmx/GetLyric?lyricId=5497&lyricCheckSum=c58a88a5cd5550b2793a408d17193af6
And is in the exact same format a $lyricxml1 (echo output: http://api.chartlyrics.com/apiv1.asmx/SearchLyric?artist=The Buzzcocks&song=Orgasm Addict)
Upvotes: 0
Views: 836
Reputation: 1064
You could try using file_get_contents()
to load the file then use simplexml_load_string()
to turn it into an object.
If you are loading a external file, like in your code example you can use curl to get the data, then convert it to an object using simplexml_load_string()
on the response.
Upvotes: 1