Simple use of XML in conjunction with PHP to create a weather query form

Source: Internet
Author: User

HTML page
<!doctypeHtml>
<Htmllang="EN" >
<Head>
<Metacharset="UTF-8" >
<title>document</Title>
</Head>
<Body>
<FormMethod= "POST" action= " weather.php "
input Span style= "COLOR: #4aa3ff" >type= "text" name= "city"/>
<input type= "submit" name=value= " query "/>
</FORM>
</BODY>
</ HTML>
HTML page does not do what style, interested in small partners can set up their own





PHP page
<?php
Header("Content-type:text/html;charset=utf-8");
//Determine if the user submits data is legitimate
If(Isset($_post[' Submit '])){
//The receiving table only son over.CityData
$city =$_post[' City '];
//Convert character encoding,Mb_convert_ecoding ("The data to be transferred","The character encoding to turn into","From what code to turn into")
$city =Mb_convert_encoding($city,' GBK ',' Utf-8 ');
//PutCityConvert to input to address barUrlof data
$city =UrlEncode($city);
//Get the interface address, find a website to see the address of the weather page
$url ="Http://php.weather.sina.com.cn/xml.php?city={$city}&password=djoyniet8234jlsk&day=0 ";
//Send Browser request
$str =File_get_contents($url);
//GeneratedXmlobject, note that it is in the form of a string
$xml =Simplexml_load_string($str);
//For relevant information,
Echo"City:".$xmlWeather->City;
Echo"<br/>";
Echo"Weather conditions:". $xml-weather->status1;
echo "<br/>";
echo " dressing advice :". $xml-weather->chy_shuoming;


}< /c2>

Simple use of XML in conjunction with PHP to create a weather query form

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.