从URL获取rss时出错?

时间:2013-05-01 14:17:16

标签: php

我有一个示例代码:

<?php 
header('Content-Type: text/html; charset=utf-8');
$doc = new DOMDocument();
$doc->load('http://www.haivl.com/rss');

$items = $doc->getElementsByTagName('item');
foreach ($items as $key => $item) {
    $titles = $item->getElementsByTagName( "title" );
    $title = $titles->item(0)->nodeValue;
    echo $title;
}
?>

我无法从此网址获取标题,为什么错误,可以帮我修复此错误!

1 个答案:

答案 0 :(得分:2)

问题是这两行

$title = $titles->item(0)->nodeValue;
echo $titles;

您将标题值分配给$title,但回显$titles$titlesDOMNodeList,无法隐式转换为字符串。你想做什么

$title = $titles->item(0)->nodeValue;
echo $title;