首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用willvincent/feed插件读取pubdate字段?

如何使用willvincent/feed插件读取pubdate字段?
EN

Stack Overflow用户
提问于 2019-01-10 23:44:12
回答 1查看 503关注 0票数 1

我使用https://github.com/willvincent/feeds来读取rss,对于所有字段,我还需要获取pubDate字段。iI没有找到它的方法(我还查看了源应用程序/库/AppRssImport.php文件),我做了一些调试,所以方法

代码语言:javascript
运行
复制
            echo '<pre>$RssItem->data[\'child\']::'.print_r($RssItem->data['child'],true).'</pre>';
            dd($RssItem->data['child']);

有下一个输出:

代码语言:javascript
运行
复制
$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字段的值,但失败。这个结构对我来说是相当奇怪的。哪一个是正确的决定?

EN

Stack Overflow用户

发布于 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,所以抓取提要的第一行可能会有所不同。

代码语言:javascript
运行
复制
$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();
}
票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54132181

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档