Salta al contenuto
  • CATEGORIES
  • La Community Connect.gt
  • Presentati alla Community
  • News Ufficiali da Connect.gt
  • Internet News
  • A Scuola Di
  • Digital Marketing
  • Intelligenza Artificiale
  • SEO & GEO
  • Web Marketing e Content
  • Google Analytics e Web Analytics
  • Google Ads & Advertising
  • YouTube
  • TikTok, Instagram e altri Social
  • Google Adsense, Affiliazioni e Guadagno
  • E-Commerce
  • Coding e Sistemistica
  • Help Center: consigli per il tuo progetto
  • Hosting e Cloud
  • Coding
  • CMS & Piattaforme Self-Hosted
  • Annunci e Collaborazioni
  • Annunci Vendita e Acquisto: Pubblicità, Domini, Link e altro
  • Collaborazioni WEB e Lavoro: offro e cerco
  • Impresa, Fisco e Leggi
  • Consulenza Legale e Professioni Web
  • Consulenza Fiscale, Imprese, Startup e P.Iva
  • Gli Off Topic
  • PC, Smartphone e altri Hardware
  • Tutti i Software
  • GT Fetish Cafè
  • Discussioni
  • 0 Non letti 0
  • Recenti
  • Hashtag
  • Popolare
  • Utenti
  • Privacy
  • Termini e condizioni
  • © 2026 Search On Media Group S.r.l.
Collassa
Connect.gt
Il network Search On
Connect.gt WMF AI Festival Accademia Advanced SEO Tool AgentCy Social Media Strategies Search Tech
Registrati Accedi
Connect.gt
Stream Interest Categorie Hashtag
  1. La community italiana di SEO, marketing digitale e AI
  2. Categorie
  3. Coding e Sistemistica
  4. Coding
  5. Php e meteo con Yahoo Weather

Php e meteo con Yahoo Weather

Pianificato Fissato Bloccato Spostato Coding
1 Post 1 Autori 1.3k Visualizzazioni 1 Seguito
  • Da Vecchi a Nuovi
  • Da Nuovi a Vecchi
  • Più Voti
Rispondi
  • Risposta alla discussione
Effettua l'accesso per rispondere
Questa discussione è stata eliminata. Solo gli utenti con diritti di gestione possono vederla.
  • A
    A
    AlessandroGi
    scritto su ultima modifica di
    User Attivo 47
    #1
    Php e meteo con Yahoo Weather

    Qualcuno ha usato le api di Yahoo Wheater?

    Ho questo script per mettere le condizioni Meteo, ma mi segnala un errore quando dichiaro l'oggetto di yahoo:

    <?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(&$controller)
        {
            $this->controller =& $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->content = file_get_contents($this->WEATHER_API_URL.$location_code.'&u='.$degreeUnit))
            {
                $result['location']=$this->GetTagAttributes('yweather:location');
                $result['condition']=$this->GetTagAttributes('yweather:condition');
                $result['units']=$this->GetTagAttributes('yweather:units');
                $result['wind']=$this->GetTagAttributes('yweather:wind');
                $result['atmosphere']=$this->GetTagAttributes('yweather:atmosphere');
                $result['astronomy']=$this->GetTagAttributes('yweather:astronomy');
                $result['geo:lat']=$this->GetTagValue('geo:lat');
                $result['geo:long']=$this->GetTagValue('geo:long');
                $result['link']=explode('*',$this->GetTagValue('link'));
                $result['pubDate']=$this->GetTagValue('pubDate');
                $result['description']=$this->GetTagValue('description');
                $result['image_url']=$this->WEATHER_IMAGE_BASE.$result['condition']['code'].'.gif';
                $forecasts=$this->GetTagAttributes('yweather:forecast');
                $result['tonight_forecast']=$forecasts[0];
                $result['tonight_forecast']['image_url']=$this->WEATHER_IMAGE_BASE.$result['tonight_forecast']['code'].'.gif';        
                $result['tomorrow_forecast']=$forecasts[1];
                $result['tomorrow_forecast']['image_url']=$this->WEATHER_IMAGE_BASE.$result['tomorrow_forecast']['code'].'.gif';
                return $result;
            }
            else
            {
                $this->errors[]='Unable to connect to yahoo api.';
                return false;
            }
        }
    
        /*
         * @param string $sTag
         * @return bool
         */
        function GetTagValue($sTag)
        {
            $aMatches = array();
                
            if (preg_match("/<$sTag>([^<]*)<\/$sTag>/i", $this->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("/<$sTag([^\/]*)\/>/i", $this->content, $aMatches))
            {
                $aResult = array();
    
                for ($i = 0; $i < count($aMatches[1]); $i++)
                {
                    $aSubMatches = array();
    
                    if (preg_match_all("/([^=]+)=\"([^\"]*)\"/i", $aMatches[1][$i], $aSubMatches))
                    {
                        for ($j = 0; $j < count($aSubMatches[1]); $j++)
                        {
                            $aResult[$i][trim($aSubMatches[1][$j])] = trim($aSubMatches[2][$j]);
                        }
                    }
                }
                $iNumResults = count($aResult);
                if ($iNumResults > 1)
                {
                    return $aResult;
                } elseif ($iNumResults == 1)
                {
                    return $aResult[0];
                }
            }
            return false;
        }
    }
    ?>
    

    Qualcuno ha usato questa classe o sa dirmi come fare per farlo funzionare?

    1 Risposta Ultima Risposta
    Miglior risposta 0
    0

    Ciao! Sembra che tu sia interessato a questa conversazione, ma non hai ancora un account.

    Stanco di dover scorrere gli stessi post a ogni visita? Quando registri un account, tornerai sempre esattamente dove eri rimasto e potrai scegliere di essere avvisato delle nuove risposte (tramite email o notifica push). Potrai anche salvare segnalibri e votare i post per mostrare il tuo apprezzamento agli altri membri della comunità.

    Con il tuo contributo, questo post potrebbe essere ancora migliore 💗

    Registrati Accedi
    Rispondi
    • Risposta alla discussione
    Effettua l'accesso per rispondere
    • Da Vecchi a Nuovi
    • Da Nuovi a Vecchi
    • Più Voti


    • Accedi

    • Non hai un account? Registrati

    • Accedi o registrati per effettuare la ricerca.
    • Primo post
      Ultimo post
    Home Accedi Registrati
    Menu
    • CATEGORIES
    • La Community Connect.gt
    • Presentati alla Community
    • News Ufficiali da Connect.gt
    • Internet News
    • A Scuola Di
    • Digital Marketing
    • Intelligenza Artificiale
    • SEO & GEO
    • Web Marketing e Content
    • Google Analytics e Web Analytics
    • Google Ads & Advertising
    • YouTube
    • TikTok, Instagram e altri Social
    • Google Adsense, Affiliazioni e Guadagno
    • E-Commerce
    • Coding e Sistemistica
    • Help Center: consigli per il tuo progetto
    • Hosting e Cloud
    • Coding
    • CMS & Piattaforme Self-Hosted
    • Annunci e Collaborazioni
    • Annunci Vendita e Acquisto: Pubblicità, Domini, Link e altro
    • Collaborazioni WEB e Lavoro: offro e cerco
    • Impresa, Fisco e Leggi
    • Consulenza Legale e Professioni Web
    • Consulenza Fiscale, Imprese, Startup e P.Iva
    • Gli Off Topic
    • PC, Smartphone e altri Hardware
    • Tutti i Software
    • GT Fetish Cafè
    • Discussioni
    • Non letti 0
    • Recenti
    • Hashtag
    • Popolare
    • Utenti
    • Privacy
    • Termini e condizioni
    • © 2026 Search On Media Group S.r.l.