PHP实现简单天气预报2015-02-28实现简单天气预报,如下图:

/**weather.php*code:*/
<?phpheader("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>From:csdn博客 风火程序员