doutuo3935 2013-05-01 14:17
浏览 17

从URL获取rss时出错?

I have a sample code:

<?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;
}
?>

I can't get title from this url, why error, can help me fix this error !

  • 写回答

1条回答 默认 最新

  • dongpu3898 2013-05-01 14:23
    关注

    The problem is these two lines

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

    You're assigning the title value to $title but echoing $titles. $titles is a DOMNodeList and can't be converted to a string implicitly. You want to do

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

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题