Question

I want to get the following information from the iTunes top 100 RSS but am having issues with the below.

function itunes(){
$itunes_feed = "https://itunes.apple.com/au/rss/topsongs/limit=100/explicit=true/xml";
$itunes_feed = file_get_contents($itunes_feed);
$itunes_feed = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $itunes_feed);
$itunes_xml = new SimpleXMLElement($itunes_feed);
$itunes_entry = $itunes_xml->entry;

    foreach($itunes_entry as $entry){
        // Get the value of the entry ID, by using the 'im' namespace within the <id> attribute
        $entry_id['im'] = $entry->id->attributes('im', TRUE);
        echo $entry_id['im']['id']."<br>";
        //echo $entry_id['artist']."<br>";
    }
}

I can get the id from <id im:id="783656917">

However I can not get the following

<im:artist href="https://itunes.apple.com/au/artist/pharrell-williams/id14934728?uo=2">Pharrell Williams</im:artist>

I want to get Pharrell Williams i have tried $entry->id->attributes->im[artist] $entry_id['artist'] and even $entry_id->artist

But no matter what I do I cannot get it to give me the artist name.

Was it helpful?

Solution

You need to cast the object to string

$value = (string)($entry->imartist);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top