Search code examples
phprssfeed

can't read rss feed with tagname has double-points on php


I want get the author from the rss-feed, but the with my code can note read this. i think the problem is at the tag-name with double-points. ( look at screenshot ).

my code:

//get first feed

function ermGetFirstFeed($feed, $language){

    //Get Feed Content
    $feed_to_array = simplexml_load_file($feed, 'SimpleXMLElement', LIBXML_NOCDATA);
    $chanel_newest = $feed_to_array->channel;

    //Get IMG Link
    $imgLink = $chanel_newest->item->imageItem->attributes()->__toString();

    //Get Date-Link
    $date = $chanel_newest->lastBuildDate->__toString();
    $newDate = new DateTime($date);
    if($language == true){
        setlocale(LC_ALL, "en_US.UTF-8");
    }
    $newDate = $newDate->format('F j,Y');

    //Get Title
    $title = $chanel_newest->item->title->__toString();

    //Get Description
    $description = $chanel_newest->item->description->__toString();

    //Get Link
    $link = $chanel_newest->item->guid->__toString();

    //Get Author
    //TODO !!!!!! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    //Create First Feed
    $firstFeed = array();
    $firstFeed = array(
            'img_link' => $imgLink,
            'date' => $newDate,
            'title' => $title,
            'description' => $description,
            'link' => $link,
            'autor' => 'empty'
        );



    return $firstFeed;
}

Data looks like this.

here is the link to the feed:

https://www.abb-conversations.com/DACH/feed

Thank you for your help


Solution

  • Add the required namespace:

    $feed_to_array = simplexml_load_file($feed, 'SimpleXMLElement', LIBXML_NOCDATA);
    $feed_to_array->registerXPathNamespace('dc', 'http://purl.org/dc/elements/1.1/');
    

    Get the desired value

    $creator = $chanel_newest->item->xpath('dc:creator')[0]->__toString();
    echo $creator;