File_get_contents: Query XML

Source: Internet
Author: User
File_get_contents: use ini_set ('User _ agent', 'mozilla/4.0 & nbsp; (compatible; & nbsp; MSIE & nbsp; 6.0; & nbsp; windows & nbsp; NT & nbsp; 5.1) '); & nbsp; // & nbsp; This file_get_contents has a strange problem in obtaining XML.
Use
Ini_set ('User _ agent', 'mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) '); // the result of this addition is the same.
$ Contents = file_get_contents ($ url );
Obtain an XML file. The result is:


2421 Shanghai
2420 Tianjin


The source code I obtained using a browser or other tools is as follows:


2421 Juan Miao
2420 Trigger


Why? One is cityid, the other is id, the other is cityname, and the other is name
------ Solution --------------------
What is your url .. You can paste it out.
------ Solution --------------------

2421 Shanghai
2420 Tianjin
2419 Beijing
2418 Chongqing
372 Shenzhen
2422 Guangzhou
.....


------ Solution --------------------
The browser or file_get_contents both have the following results:


2421 Shanghai
2420 Tianjin
2419 Beijing
2418 Chongqing
...........................

------ Solution --------------------
The author's browser encoding problem

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.