使用 SimpleXmlElement 从 wordpress RSS 提要获取作者的问题 [英] Problem getting author from a wordpress RSS feed using SimpleXmlElement

查看:49
本文介绍了使用 SimpleXmlElement 从 wordpress RSS 提要获取作者的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我正在尝试解析来自 wordpress 博客的 RSS 提要.到目前为止一切都按预期工作,这是我的代码

Hay, i'm trying to parse an RSS feed from a wordpress blog. So far everything is working as expected, here's my code

<?php
    $feedUrl = "FEED URL"; 
    $rawFeed = file_get_contents($feedUrl); 
    $xml = new SimpleXmlElement($rawFeed);
    $channel = $xml->channel;
    $items = $channel->item;
    foreach($items as $item){
        echo "<a href='".$item->link."'>".$item->title."</a>";
        echo $item->description;
        echo $item->pubDate;

    }       

?>

但是,我似乎在获取帖子的作者时遇到了问题.数据必须在某处,因为当 Safari 呈现提要时,作者会出现.

However, i seem to be having issues getting the Author of the post. The data has got to be somewhere because when Safari renders the feed the author appears.

这是我的 RSS 提要

Here is my RSS feed

SimpleXMLElement Object
(
[@attributes] => Array
    (
        [version] => 2.0
    )

[channel] => SimpleXMLElement Object
    (
        [title] => My Blog title
        [link] => http://blog.com/new/blog
        [description] => Just another WordPress site
        [lastBuildDate] => Thu, 22 Jul 2010 08:02:19 +0000
        [language] => en
        [generator] => http://wordpress.org/?v=3.0
        [item] => Array
            (
                [0] => SimpleXMLElement Object
                    (
                        [title] => Second post
                        [link] => http://blog.com/new/blog/?p=5
                        [comments] => http://blog.com/new/blog/?p=5#comments
                        [pubDate] => Thu, 22 Jul 2010 08:02:19 +0000
                        [category] => SimpleXMLElement Object
                            (
                            )

                        [guid] => http://blog.com/new/blog/?p=5
                        [description] => SimpleXMLElement Object
                            (
                            )

                    )

                [1] => SimpleXMLElement Object
                    (
                        [title] => Hello world!
                        [link] => http://blogl.com/new/blog/?p=1
                        [comments] => http://blog.com/new/blog/?p=1#comments
                        [pubDate] => Thu, 22 Jul 2010 07:22:40 +0000
                        [category] => SimpleXMLElement Object
                            (
                            )

                        [guid] => http://blog.com/new/blog/?p=1
                        [description] => SimpleXMLElement Object
                            (
                            )

                    )

            )

    )

)

任何帮助都会很棒!

谢谢

推荐答案

在 Wordpress RSS 提要中,作者信息位于 标签中.看看这是否也适用于您的 Feed.

In a Wordpress RSS feed, the author info is in the <dc:creator> tag. Check out whether that applies to your feed as well.

XML 解析器因为标签名称中的冒号而吞下了标签.

The XML parser swallows the tag because of the colon in the tag name.

请参阅这个问题,了解如何显示这些标签

See this question for how to get those tags to display as well.

这篇关于使用 SimpleXmlElement 从 wordpress RSS 提要获取作者的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆