PHP code example of sockstack / weather

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

    

sockstack / weather example snippets


use Sockstack\Weather\Weather;

$weather = new Weather();
//json
$response = $weather->get("北京市");

//array
$response = $weather->get("北京市", true);
json
{
    "data": {
        "yesterday": {
            "date": "30日星期二",
            "high": "高温 16℃",
            "fx": "北风",
            "low": "低温 1℃",
            "fl": "<![CDATA[<3级]]>",
            "type": "晴"
        },
        "city": "北京",
        "aqi": "29",
        "forecast": [
            {
                "date": "31日星期三",
                "high": "高温 17℃",
                "fengli": "<![CDATA[<3级]]>",
                "low": "低温 3℃",
                "fengxiang": "西南风",
                "type": "晴"
            },
            {
                "date": "1日星期四",
                "high": "高温 17℃",
                "fengli": "<![CDATA[<3级]]>",
                "low": "低温 3℃",
                "fengxiang": "南风",
                "type": "晴"
            },
            {
                "date": "2日星期五",
                "high": "高温 18℃",
                "fengli": "<![CDATA[<3级]]>",
                "low": "低温 5℃",
                "fengxiang": "南风",
                "type": "晴"
            },
            {
                "date": "3日星期六",
                "high": "高温 17℃",
                "fengli": "<![CDATA[<3级]]>",
                "low": "低温 7℃",
                "fengxiang": "南风",
                "type": "多云"
            },
            {
                "date": "4日星期天",
                "high": "高温 14℃",
                "fengli": "<![CDATA[3-4级]]>",
                "low": "低温 6℃",
                "fengxiang": "北风",
                "type": "多云"
            }
        ],
        "ganmao": "天凉,昼夜温差较大,较易发生感冒,请适当增减衣服,体质较弱的朋友请注意适当防护。",
        "wendu": "15"
    },
    "status": 1000,
    "desc": "OK"
}