문제

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?

도움이 되었습니까?

해결책

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'); 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top