无法用 PHP 解析 RSS XML [英] Can't Parse RSS XML with PHP

查看:60
本文介绍了无法用 PHP 解析 RSS XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些 RSS,我想从这个 URL 解析:http://weather.yahooapis.com/forecastrss?w=12797541

I have some RSS that I am trying to parse from this URL: http://weather.yahooapis.com/forecastrss?w=12797541

但是当我尝试使用 PHP 解析它时:

But when I try to parse it using PHP doing this:

$yahoo_response = new SimpleXMLElement($yahoo_url , 0, true);

echo $yahoo_response->rss->channel->item->title;
echo $yahoo_response->rss->channel->item->description;

没有任何输出.有谁知道我在这里做错了什么?我只需要当前的预测位.

Nothing gets outputed. Does anyone know what I am doing wrong here? I just need the current forecast bit.

谢谢,亚历克斯

推荐答案

根元素是 ,由你加载到 SimpleXmlElement 表示代码>$yahoo_response.

The root element is <rss>, which is represented by the SimpleXmlElement you loaded into $yahoo_response.

echo $yahoo_response->getName();  // rss

当你应该做的时候,你正在尝试做:

You are trying to do <rss><rss> when you should do:

echo $yahoo_response->channel->item->title;
echo $yahoo_response->channel->item->description;

这篇关于无法用 PHP 解析 RSS XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆