PHP code example of cosyphp / weather
1. Go to this page and download the library: Download cosyphp/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/ */
cosyphp / weather example snippets
osyphp\Weather\Weather;
$key = 'a775cc62fc87a9d0d9106d63b9397d41';
$w = new Weather($key);
echo "获取实时天气:\n";
$response = $w->getWeather('郑州');
echo json_encode($response, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
echo "\n\n获取天气预报:\n";
$response = $w->getWeather('郑州', 'all');
echo json_encode($response, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
echo "\n\n获取实时天气(XML):\n";
echo $w->getWeather('深圳', 'base', 'XML');