[英]yahoo weather Api
I would like to get the temperature value from Yahoo's weather API. I have found a tutorial but in the tutorial he is getting a different value.我想从 Yahoo 的天气 API 获取温度值。我找到了一个教程,但在教程中他得到了不同的值。 Could some one help me modify the tutorial that it could get the temp value from Yahoo's weather RSS feed?
有人可以帮助我修改教程,使其可以从 Yahoo 的天气 RSS 提要中获取临时值吗?
<yweather:condition text="Partly Cloudy" code="30" temp="3"
date="Mon, 09 Apr 2012 3:48 pm EEST" />
RSS feed: http://weather.yahooapis.com/forecastrss?w=566473&u=c RSS 提要: http://weather.yahooapis.com/forecastrss?w=566473&u=c
The tutorial I followed: http://css-tricks.com/using-weather-data-to-change-your-websites-apperance-through-php-and-css/我遵循的教程: http://css-tricks.com/using-weather-data-to-change-your-websites-apperance-through-php-and-css/
If some one has a better solution for getting the value don't hesitate to say it.如果有人有更好的解决方案来获得价值,请毫不犹豫地说出来。 :)
:)
This seems pretty straightforward.这看起来很简单。 From the tutorial:
从教程:
Since the only bit of information we care about is the
yweather:condition
element'stext
attribute, we're going to avoid creating an XML parsing object and use a short regular expression.由于我们唯一关心的信息是
yweather:condition
元素的text
属性,我们将避免创建 XML 解析 object 并使用短正则表达式。
So, just look at the line with the regular expression:因此,只需查看带有正则表达式的行:
$weather_class = format_result( get_match( '/<yweather:condition text="(.*)"/isU', $data ) );
This is actually a bad regular expression because it assumes text
will always be the first attribute (and that there'll always be that weird double-space. Here's a regular expression that will get the temp
attribute regardless of where it falls:这实际上是一个糟糕的正则表达式,因为它假定
text
将始终是第一个属性(并且总会有那个奇怪的双空格。这是一个正则表达式,无论它位于何处,它都会获取temp
属性:
/<yweather:condition\s+(?:.*\s)?temp="(.+)"/isU
Substitute that for the regular expression given to get_match()
and you should be good to go.将其替换给
get_match()
的正则表达式,您应该可以得到 go。
Oh, and lest I be kicked off SO for not saying so: Attempting to parse arbitrary哦,以免我因为没有这么说而被开除:Attempting to parse arbitrary
HTML XML with regular expressions is the path to madness . HTML
XML 正则表达式是疯狂之路。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.