可以使用 PHP 的 CURL 库来访问天气 API,然后解析返回的 JSON 数据来获取今日天气信息。需要注意的是,需要先申请 API Key 才能使用天气 API。
以下是一个简单的示例:
<?php
// 设置 API Key
$apiKey = "YOUR_API_KEY";
// 设置城市
$city = "Beijing";
// 构造请求 URL
$url = "http://api.openweathermap.org/data/2.5/weather?q=" . $city . "&appid=" . $apiKey;
// 初始化 CURL
$ch = cu