0

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

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.

Thanks, Alex

1
  • echo (string) $yahoo_response->rss->channel->item->title; Commented Feb 24, 2011 at 6:37

2 Answers 2

2

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;
Sign up to request clarification or add additional context in comments.

Comments

1

I've found that RSS feeds are best parsed using a library.

I've had much success with magpieRSS.

But your immediate problem is that you are passing a URL to simplexml, instead of the xml itself.

try $xml = file_get_contents($yahoo_url); first.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.