使用SimpleXmlElement从wordpress RSS提要获取作者的问题

时间:2010-07-22 09:49:24

标签: php wordpress parsing rss

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

<?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呈现作者出现的提要时。

这是我的RSS提要

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
                            (
                            )

                    )

            )

    )

任何帮助都会很棒!

由于

1 个答案:

答案 0 :(得分:3)

在Wordpress RSS Feed中,作者信息位于<dc:creator>标记中。检查这是否也适用于您的Feed。

由于标记名称中的冒号,XML解析器会吞下标记。

有关如何显示这些标记的信息,请参阅this question