PHP code example of zhongdj1 / weather

1. Go to this page and download the library: Download zhongdj1/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/ */

    

zhongdj1 / weather example snippets


use Zhongdj1\Weather\Weather;

$key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';

$weather = new Weather($key);

$response = $weather->getLiveWeather('深圳');

$response = $weather->getLiveWeather('深圳', 'xml');

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

    .
    .
    .
    public function edit(Weather $weather) 
    {
        $response = $weather->getLiveWeather('深圳');
    }
    .
    .
    .

    .
    .
    .
    public function edit() 
    {
        $response = app('weather')->getLiveWeather('深圳');
    }
    .
    .
    .


$response = $weather->getForecastsWeather('深圳');
xml
<response>
    <status>1</status>
    <count>1</count>
    <info>OK</info>
    <infocode>10000</infocode>
    <lives type="list">
        <live>
            <province>广东</province>
            <city>深圳市</city>
            <adcode>440300</adcode>
            <weather>中雨</weather>
            <temperature>27</temperature>
            <winddirection>西南</winddirection>
            <windpower>5</windpower>
            <humidity>94</humidity>
            <reporttime>2019-08-14 14:00:00</reporttime>
        </live>
    </lives>
</response>