<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Php e meteo con Yahoo Weather]]></title><description><![CDATA[<p dir="auto">Qualcuno ha usato le api di Yahoo Wheater?</p>
<p dir="auto">Ho questo script per mettere le condizioni Meteo, ma mi segnala un errore quando dichiaro l'oggetto di yahoo:</p>
<pre><code>&lt;?php 
/* Yahoo! Weather API component for Cakephp
 * @author Arash Hemmat www.hemmat.biz
 * @version 1.2  some bugs has been fixed.
 * @license http://www.opensource.org/licenses/mit-license.php
 * Special thanks to "Ed Eliot" (http://www.ejeliot.com/blog/38) ,I used his code for this component.
 */

/*
 * Yahoo weather component class
 */
[COLOR=Red]class yahooWeatherComponent extends Object[/COLOR]
{
    /*
     * @var bool
     */
    var $controller = true;

    /*
     * @var array
     */
    var $errors=array();

    /*
     * @var string
     */
    var $content;

    /*
     * The url of Yahoo! weather API
     * @var string
     */
    var $WEATHER_API_URL='http://weather.yahooapis.com/forecastrss?p=';

    /*
     * THe address for images, you need to change this if you want to use your own images.
     * @var string
     */
    var $WEATHER_IMAGE_BASE='http://l.yimg.com/us.yimg.com/i/us/we/52/';
    
    /*
     * initialization
     * @param bool $controller
     */
    function startup(&amp;$controller)
    {
        $this-&gt;controller =&amp; $controller;
    }

    /*
     * Get the weather information for given location code
     * @param string $locationCode a code that represent a location in Yahoo weather system
     * @param string $degreeUnit it could be f: Fahrenheit or c: Celsius
     * @param bool $translate this parametr indicates if the result should be translated of not
     * @return array|bool $result
     */
    function get_weather($locationCode,$degreeUnit='c')
    {
        if($this-&gt;content = file_get_contents($this-&gt;WEATHER_API_URL.$location_code.'&amp;u='.$degreeUnit))
        {
            $result['location']=$this-&gt;GetTagAttributes('yweather:location');
            $result['condition']=$this-&gt;GetTagAttributes('yweather:condition');
            $result['units']=$this-&gt;GetTagAttributes('yweather:units');
            $result['wind']=$this-&gt;GetTagAttributes('yweather:wind');
            $result['atmosphere']=$this-&gt;GetTagAttributes('yweather:atmosphere');
            $result['astronomy']=$this-&gt;GetTagAttributes('yweather:astronomy');
            $result['geo:lat']=$this-&gt;GetTagValue('geo:lat');
            $result['geo:long']=$this-&gt;GetTagValue('geo:long');
            $result['link']=explode('*',$this-&gt;GetTagValue('link'));
            $result['pubDate']=$this-&gt;GetTagValue('pubDate');
            $result['description']=$this-&gt;GetTagValue('description');
            $result['image_url']=$this-&gt;WEATHER_IMAGE_BASE.$result['condition']['code'].'.gif';
            $forecasts=$this-&gt;GetTagAttributes('yweather:forecast');
            $result['tonight_forecast']=$forecasts[0];
            $result['tonight_forecast']['image_url']=$this-&gt;WEATHER_IMAGE_BASE.$result['tonight_forecast']['code'].'.gif';        
            $result['tomorrow_forecast']=$forecasts[1];
            $result['tomorrow_forecast']['image_url']=$this-&gt;WEATHER_IMAGE_BASE.$result['tomorrow_forecast']['code'].'.gif';
            return $result;
        }
        else
        {
            $this-&gt;errors[]='Unable to connect to yahoo api.';
            return false;
        }
    }

    /*
     * @param string $sTag
     * @return bool
     */
    function GetTagValue($sTag)
    {
        $aMatches = array();
            
        if (preg_match("/&lt;$sTag&gt;([^&lt;]*)&lt;\/$sTag&gt;/i", $this-&gt;content, $aMatches))
        {
            $aResult = array();
            $aResult['value'] = $aMatches[1];
            return trim($aMatches[1]);
        }
        return false;
    }

    /*
     * @param string $sTag
     * @return string $aResult
     */
    function GetTagAttributes($sTag)
    {
        $aMatches = array();
            
        if (preg_match_all("/&lt;$sTag([^\/]*)\/&gt;/i", $this-&gt;content, $aMatches))
        {
            $aResult = array();

            for ($i = 0; $i &lt; count($aMatches[1]); $i++)
            {
                $aSubMatches = array();

                if (preg_match_all("/([^=]+)=\"([^\"]*)\"/i", $aMatches[1][$i], $aSubMatches))
                {
                    for ($j = 0; $j &lt; count($aSubMatches[1]); $j++)
                    {
                        $aResult[$i][trim($aSubMatches[1][$j])] = trim($aSubMatches[2][$j]);
                    }
                }
            }
            $iNumResults = count($aResult);
            if ($iNumResults &gt; 1)
            {
                return $aResult;
            } elseif ($iNumResults == 1)
            {
                return $aResult[0];
            }
        }
        return false;
    }
}
?&gt;
</code></pre>
<p dir="auto">Qualcuno ha usato questa classe o sa dirmi come fare per farlo funzionare?</p>
]]></description><link>https://dev.connect.gt/topic/66329/php-e-meteo-con-yahoo-weather</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Dec 2026 07:47:44 GMT</lastBuildDate><atom:link href="https://dev.connect.gt/topic/66329.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 18 Mar 2008 10:57:42 GMT</pubDate><ttl>60</ttl></channel></rss>