We will see that many websites can display the local weather in real time. let me tell you how to do this in real time, you can use the googleaip interface to obtain the weather conditions of different cities and display them on your website. Se. phpnbsp...
We will see that many websites can display the local weather in real time. let me tell you how to do this in real time, you can use the google aip interface to obtain the weather conditions of different cities and display them on your website.
Se. php
The code is as follows: |
|
$ City = $ _ GET ['city']; $ Data = createXml ($ city ); $ Xml = simplexml_load_string ($ data ); Header ("Content-type: text/xml "); Echo $ xml-> asXML (); // Generate XML data Function createXml ($ city) { // Google Weather API $ Weather = simplexml_load_file ("http://www.google.com/ig/api? Weather = {$ city }"); If (isset ($ weather-> forecast_conditions )) { $ Low = f2c ($ weather-> forecast_conditions-> low ['data']); $ High = f2c ($ weather-> forecast_conditions-> high ['data']); Return" N {$ City} N {$ Low} N {$ High} N "; } Else { Return" N N "; } } // Degrees Fahrenheit to degree Celsius Function f2c ($ fahrenhite) { Return floor ($ fahrenhite-32)/1.8 ); } |
Client c. php
The code is as follows: |
|
Weather query
If (! Empty ($ _ POST ['city']) { $ City = $ _ POST ['city']; $ Xml = simplexml_load_file ("http: // 127.0.0.1/rest/se. php? City = {$ city }"); $ Html ="City: {$ xml-> city} N "; $ Html. ="Low: {$ xml-> low} N "; $ Html. ="High: {$ xml-> high} N "; Echo $ html; } ?>
|
Article address:
Reprint at will ^ please include the address of this article!