我使用https://github.com/willvincent/feeds来读取rss,对于所有字段,我还需要获取pubDate字段。iI没有找到它的方法(我还查看了源应用程序/库/AppRssImport.php文件),我做了一些调试,所以方法
echo '<pre>$RssItem->data[\'child\']::'.print_r($RssItem->data['child'],true).'</pre>';
dd($RssItem->data['child']);有下一个输出:
$RssItem->data['child']::Array
(
[] => Array
(
[title] => Array
(
[0] => Array
(
[data] => Man died 'in agony' after stroke amid ambulance delays
[attribs] => Array
(
)
[xml_base] =>
[xml_base_explicit] =>
[xml_lang] =>
)
)
[description] => Array
(
[0] => Array
(
[data] => Michelle Lane has PTSD and flashbacks of her husband screaming in pain as they went to hospital by car.
[attribs] => Array
(
)
[xml_base] =>
[xml_base_explicit] =>
[xml_lang] =>
)
)
[link] => Array
(
[0] => Array
(
[data] => https://www.bbc.co.uk/news/uk-england-nottinghamshire-46795776
[attribs] => Array
(
)
[xml_base] =>
[xml_base_explicit] =>
[xml_lang] =>
)
)
[guid] => Array
(
[0] => Array
(
[data] => https://www.bbc.co.uk/news/uk-england-nottinghamshire-46795776
[attribs] => Array
(
[] => Array
(
[isPermaLink] => true
)
)
[xml_base] =>
[xml_base_explicit] =>
[xml_lang] =>
)
)
[pubDate] => Array
(
[0] => Array
(
[data] => Thu, 10 Jan 2019 10:02:22 GMT
[attribs] => Array
(
)
[xml_base] =>
[xml_base_explicit] =>
[xml_lang] =>
)
)
)
[http://search.yahoo.com/mrss/] => Array
(
[thumbnail] => Array
(
[0] => Array
(
[data] =>
[attribs] => Array
(
[] => Array
(
[width] => 1024
[height] => 576
[url] => http://c.files.bbci.co.uk/15CE0/production/_105121398_michelle-tony.jpg
)
)
[xml_base] =>
[xml_base_explicit] =>
[xml_lang] =>
)
)
)
)https://imgur.com/a/wTmd9cV I尝试读取pubDate字段的值,但失败。这个结构对我来说是相当奇怪的。哪一个是正确的决定?
发布于 2019-02-17 14:47:31
可以使用get_date()方法获取pubDate的值
https://github.com/willvincent/feeds这个插件只是对SimplePie php扩展的一个包装。您可以在SimplePie文档中查找所有其他可用的方法。http://simplepie.org/api/class-SimplePie_Item.html。
一个可用的代码可能是这样的。我使用了laravel,所以抓取提要的第一行可能会有所不同。
$feed = Feeds::make('https://www.example.com/feed/');
$items = $feed->get_items();
foreach( $items as $key => $item ) {
$title = $item->get_title();
$guid = $item->get_id();
$pub_date = $item->get_date();
}https://stackoverflow.com/questions/54132181
复制相似问题