1

我正在尝试从 RSS 提要中获取信息,并且我已经使用 PHP 和 Jquery 达到了我想要的效果,但我想 cron 它,并且目前我的应用程序开始使用 .js,我的主机说无法启动与 cron。

如果我使用 SimpleXML_load_file,它会带来一切,接受里面的属性<item>....</item>和一个孩子<a10:updated>

下面是一段生料:

SimpleXMLElement 对象([@attributes] => 数组([version] => 2.0)

[channel] => SimpleXMLElement Object
    (
        [title] => Bills from current Parliamentary Session
        [link] => http://services.parliament.uk/bills
        [description] => SimpleXMLElement Object
            (
            )

        [item] => Array
            (
                [0] => SimpleXMLElement Object
                    (
                        [guid] => http://services.parliament.uk/bills/2013-14/finance.html
                        [link] => http://services.parliament.uk/bills/2013-14/finance.html
                        [category] => Array
                            (
                                [0] => Commons
                                [1] => Government Bill
                            )

                        [title] => Finance
                        [description] => A Bill To grant certain duties, to alter other duties, and to amend the law relating to the National Debt and the Public Revenue, and to make further provision in connection with finance.
                    )

                [1] => SimpleXMLElement Object
                    (
                        [guid] => http://services.parliament.uk/bills/2013-14/humberbridge.html
                        [link] => http://services.parliament.uk/bills/2013-14/humberbridge.html
                        [category] => Array
                            (
                                [0] => Lords
                                [1] => Private Bill
                            )

                        [title] => Humber Bridge
                        [description] => A Bill to amend the constitution of the Humber Bridge Board and to confer new borrowing and other powers on it; to make new provision for the recovery of any deficit of the Board from local authorities in the area; to confer new powers for the setting and revision of tolls and to make other provision for and in connection with the operation of the bridge; and for connected purposes.
                    )

这是 rss 提要:http ://services.parliament.uk/bills/AllBills.rss

有没有另一种方法来获取原始 rss 并添加所有内容?

4

1 回答 1

2

print_r()对 SimpleXML 对象的使用是不可靠的。它并不总是显示完整的结构。

您的<a10:updated>元素使用需要特殊处理的 XML 命名空间。以下是如何访问它的示例:

$obj = simplexml_load_file(....);
foreach($obj->channel->item as $item)
{
    echo $item->children('http://www.w3.org/2005/Atom')->updated;
}

如您所见,您必须将a10命名空间的值传递给children(). 命名空间定义可以在 XML 的顶部找到:

xmlns:a10="http://www.w3.org/2005/Atom"

于 2013-06-07T10:02:51.427 回答