Get data from accuweather api url



PHP Snippet 1:

<?php
            
    function curl( $url=false ){
        $cacert='c:/wwwroot/cacert.pem';
        
        $curl=curl_init();
        if( parse_url( $url, PHP_URL_SCHEME )=='https' ){
            curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, true );
            curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, 2 );
            curl_setopt( $curl, CURLOPT_CAINFO, $cacert );
        }

        curl_setopt( $curl, CURLOPT_URL, trim( $url ) );
        curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true );
        curl_setopt( $curl, CURLOPT_FAILONERROR, true );
        curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
        curl_setopt( $curl, CURLOPT_TIMEOUT, 60 );
        curl_setopt( $curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; Win64; x64)' );
        curl_setopt( $curl, CURLOPT_ENCODING, '' );

        $res=(object)array(
            'response'  =>  curl_exec( $curl ),
            'status'    =>  curl_getinfo( $curl, CURLINFO_RESPONSE_CODE ),
            'info'      =>  (object)curl_getinfo( $curl ),
            'errors'    =>  curl_error( $curl )
        );
        curl_close( $curl );
        return $res;
    }
    
    
    $url='https://dataservice.accuweather.com/forecasts/v1/daily/1day/55488?apikey=0NSY9T1tFGo0NIXOYp23lro8DsuOcwPJ';
    $res=curl( $url );
    if( $res->status==200 ){
        printf('<pre>%s</pre>',print_r( json_decode( $res->response ),true ) );
    }
    
?>

PHP Snippet 2:

stdClass Object
(
    [Headline] => stdClass Object
        (
            [EffectiveDate] => 2022-01-14T07:00:00-05:00
            [EffectiveEpochDate] => 1642161600
            [Severity] => 4
            [Text] => Turning much colder today and tomorrow
            [Category] => cooler
            [EndDate] => 2022-01-15T19:00:00-05:00
            [EndEpochDate] => 1642291200
            [MobileLink] => http://www.accuweather.com/en/ca/toronto/m5h/daily-weather-forecast/55488?lang=en-us
            [Link] => http://www.accuweather.com/en/ca/toronto/m5h/daily-weather-forecast/55488?lang=en-us
        )

    [DailyForecasts] => Array
        (
            [0] => stdClass Object
                (
                    [Date] => 2022-01-13T07:00:00-05:00
                    [EpochDate] => 1642075200
                    [Temperature] => stdClass Object
                        (
                            [Minimum] => stdClass Object
                                (
                                    [Value] => 12
                                    [Unit] => F
                                    [UnitType] => 18
                                )

                            [Maximum] => stdClass Object
                                (
                                    [Value] => 34
                                    [Unit] => F
                                    [UnitType] => 18
                                )

                        )

                    [Day] => stdClass Object
                        (
                            [Icon] => 19
                            [IconPhrase] => Flurries
                            [HasPrecipitation] => 
                        )

                    [Night] => stdClass Object
                        (
                            [Icon] => 43
                            [IconPhrase] => Mostly cloudy w/ flurries
                            [HasPrecipitation] => 
                        )

                    [Sources] => Array
                        (
                            [0] => AccuWeather
                        )

                    [MobileLink] => http://www.accuweather.com/en/ca/toronto/m5h/daily-weather-forecast/55488?lang=en-us
                    [Link] => http://www.accuweather.com/en/ca/toronto/m5h/daily-weather-forecast/55488?lang=en-us
                )

        )

)