代码之家  ›  专栏  ›  技术社区  ›  mrduclaw

用PHP解析RSS2

  •  4
  • mrduclaw  · 技术社区  · 15 年前

    我正在尝试从我的一个站点获取RSS2提要的内容,并在另一个站点中使用它。

    饲料是 here . 我使用的代码取自 this 不错的网站,修改如下:

    $doc = new DOMDocument();
    $doc->load('http://tripleax.com/john/?feed=rss2');
    $arrFeeds = array();
    foreach ($doc->getElementsByTagName('item') as $node) {
        print('<div style="width:100%" class="option"><strong>');
        $a = $node->getElementsByTagName('title')->item(0)->nodeValue;
        print("$a");
        print('</strong><br /><span class="option">');
        $a = $node->getElementsByTagName('description')->item(0)->nodeValue;
        print("$a");`
    }
    

    $node->getElementsByTagName('description')->item(0)->nodeValue $node->getElementsByTagName('content')->item(0)->nodeValue content:encoded 也不是更好。

    有人能告诉我解决这个问题的正确方向吗?

    谢谢!

    2 回复  |  直到 15 年前
        1
  •  2
  •   rkulla    15 年前

    您需要getElementsByTagnames()

        2
  •  3
  •   mrduclaw    15 年前

    你真傻!使用 $node->getElementsByTagName('encoded')->item(0)->nodeValue