Question

I'm looking for a quick way to get only the condition code from Yahoo with PHP. I use my WOEID code to get the feed for my city's weather and in the XML response, I see this:

<yweather:condition text="Mostly Cloudy" code="28" temp="33" date="Tue, 14 May 2013 10:30 am ICT"/> 

The thing is I only want to get the code (here in the example is 28), so that it is convenient to work with the conditions. What could be the simplest way to get this tiny bit of data?

Was it helpful?

Solution

You can get it using DOMDocument:

$doc = new DOMDocument();
@$doc->loadXML('<yweather:condition text="Mostly Cloudy" code="28" temp="33" date="Tue, 14 May 2013 10:30 am ICT"/>');
$node = $doc->getElementsByTagName('condition');
echo $node->item(0)->getAttribute('code'); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top