PHP code example of lepig / weather

1. Go to this page and download the library: Download lepig/weather library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lepig / weather example snippets


use Lepig\Weather\Weather;

$key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';

$weather = new Weather($key);

$weather->getWeather('滁州');

$weather->getWeather('滁州', 'all');

$weather->getLiveWeather('滁州');

$weather->getForecastsWeather('滁州');

array | string   getWeather(string $city, string $type = 'base', string $format = 'json')

'weather' => [
        'key' => env('WEATHER_API_KEY')
    ]

WEATHER_API_KEY=xxxxxxxxxxxxxxxxxxxxx

public function show(Weather $weather, $city)
{
    return $weather->getWeather($city);
}

public function show($city)
{
    return app('weather')->getWeather($city, 'all', 'xml');
}
json
{
    "status": "1",
    "count": "1",
    "info": "OK",
    "infocode": "10000",
    "forecasts": [
        {
            "city": "滁州市",
            "adcode": "341100",
            "province": "安徽",
            "reporttime": "2019-02-19 11:17:22",
            "casts": [
                {
                    "date": "2019-02-19",
                    "week": "2",
                    "dayweather": "多云",
                    "nightweather": "多云",
                    "daytemp": "5",
                    "nighttemp": "2",
                    "daywind": "西北",
                    "nightwind": "西北",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                },
                {
                    "date": "2019-02-20",
                    "week": "3",
                    "dayweather": "小雨",
                    "nightweather": "阴",
                    "daytemp": "6",
                    "nighttemp": "3",
                    "daywind": "东北",
                    "nightwind": "东北",
                    "daypower": "4",
                    "nightpower": "4"
                },
                {
                    "date": "2019-02-21",
                    "week": "4",
                    "dayweather": "小雨",
                    "nightweather": "中雨",
                    "daytemp": "10",
                    "nighttemp": "0",
                    "daywind": "东北",
                    "nightwind": "东北",
                    "daypower": "4",
                    "nightpower": "4"
                },
                {
                    "date": "2019-02-22",
                    "week": "5",
                    "dayweather": "多云",
                    "nightweather": "晴",
                    "daytemp": "4",
                    "nighttemp": "0",
                    "daywind": "北",
                    "nightwind": "北",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                }
            ]
        }
    ]
}