无法读取带有标记名的 rss 提要在 php 上有双点
can't read rss feed with tagname has double-points on php
我想从 rss-feed 中获取作者,但是使用我的代码可以注意阅读这个。我认为问题出在带有双点的标签名称上。 (看截图)。
我的代码:
//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.
这里是 link 供稿:
https://www.abb-conversations.com/DACH/feed
感谢您的帮助
添加所需的命名空间:
$feed_to_array = simplexml_load_file($feed, 'SimpleXMLElement', LIBXML_NOCDATA);
$feed_to_array->registerXPathNamespace('dc', 'http://purl.org/dc/elements/1.1/');
得到想要的值
$creator = $chanel_newest->item->xpath('dc:creator')[0]->__toString();
echo $creator;
我想从 rss-feed 中获取作者,但是使用我的代码可以注意阅读这个。我认为问题出在带有双点的标签名称上。 (看截图)。
我的代码:
//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.
这里是 link 供稿:
https://www.abb-conversations.com/DACH/feed
感谢您的帮助
添加所需的命名空间:
$feed_to_array = simplexml_load_file($feed, 'SimpleXMLElement', LIBXML_NOCDATA);
$feed_to_array->registerXPathNamespace('dc', 'http://purl.org/dc/elements/1.1/');
得到想要的值
$creator = $chanel_newest->item->xpath('dc:creator')[0]->__toString();
echo $creator;