温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

php中如何利用中国天气预报接口实现简单天气预报

发布时间:2021-09-29 17:36:32 来源:亿速云 阅读:204 作者:小新 栏目:开发技术

小编给大家分享一下php中如何利用中国天气预报接口实现简单天气预报,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

代码如下:

<?php
header("content-type:text/html;charset=utf-8");
$weather = file_get_contents("http://www.weather.com.cn/data/sk/101280601.html");
echo $weather;
?>

代码如下:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gbk" />
<style type="text/css">
.all span {font:bold 30px/50px "宋体";color:red;}
</style>
<title>天气预报</title>
</head>
<body>
<div class="all">
这里是:<span class="place">城市</span>,
气温是<span class="temp">气温</span>,
风向:<span class="wind">风向</span>,
风力:<span class="windPower">风力</span>
</div>
<script type="text/javascript" src="http://127.0.0.1/jquery.js"></script>
<script type="text/javascript">
$(function () {
$.ajax({
//请求的地址
url : "http://127.0.0.1/weather.php",
//请求成功后执行的函数
success : function (data) {
//用eval()解析返回来的数据,将字符串转成JSON格式
var oD = eval('('+data+')');
//用jquery-1.8.2获取元素
var $place = $(".place"),
$temp = $(".temp"),
$wind = $(".wind"),
$windPower = $(".windPower");
//将返回来的数据放到相应的位置
$place.html(oD["weatherinfo"]["city"]);
$temp.html(oD["weatherinfo"]["temp"] + "°");
$wind.html(oD["weatherinfo"]["WD"]);
$windPower.html(oD["weatherinfo"]["WS"]);
}
});
})
</script>
</body>
</html>

以上是“php中如何利用中国天气预报接口实现简单天气预报”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php
AI