This article mainly introduces the use of China weather forecast interface to achieve a simple weather forecast example, we refer to the use of the bar
Code as follows: <?php header ("Content-type:text/html;charset=utf-8"); $weather = file_get_contents ("http://www.weather.com.cn/data/sk/101280601.html"); echo $weather?> code as follows: <html> <head> <meta http-equiv= "Content-type" content= " TEXT/HTML;CHARSET=GBK "/> <style type= text/css" > all span {font:bold 30px/50px "Arial"; color:red > <title> Weather </title> </head> <body> <div class= "All" > This is: <span class= "Place" > City </span>, the temperature is <span class= "temp" > Temperature </span> Wind Direction: <span class= "Wind" > Direction </span> Wind: <span class= "Windpower" > Wind </span> </div> <script type= "Text/javascript" src= "HTTP://127.0.0.1/" Jquery.js "></script> <script type=" Text/javascript "> $ (function () {$.ajax ({//Requested address URL:" http:// 127.0.0.1/weather.php ",///////////////////////////////////////////////////////Success:function '); Get element var $place with jquery-1.8.2 = $ ('. Place '), $temp = $ (". Temp"), $wind = $ (". Wind"), $windPower = $ (". Windpower"); Place the returned data in the appropriate location $place. html (od["Weatherinfo"] ["City"]); $temp. HTML (od["Weatherinfo"] ["temp"] + "°"); $wind. HTML (od["Weatherinfo"] ["WD"]); $windPower. HTML (od["Weatherinfo"] ["WS"]); } }); }) </script> </body> </html>