I started to touch php and encountered problems when parsing xml.

Source: Internet
Author: User
When I first started to touch php, I encountered a problem when parsing xml. This post was last edited by yxxue from 2012-11-2518: 57: 42. the remote XML document format is as follows: & lt ;? Xml & nbsp; version = "1.0" & nbsp; encoding = "UTF-8" & nbsp ;? & Gt; & nbsp; & encountered a problem when parsing xml in php
At the end of this post, the remote XML document format was edited by yxxue at 18:57:42, January 25:

 
 
Username = "u1" sex = "1" nickname = "Maltose"
Score = "0" province = "" city = "" area = ""/>



I got this XML in PHP as follows:
You can use the gethttpdata method you wrote to avoid program errors when access to remote servers fails.

$ Login_interface_url = "http://www.1.com/1.xml ";
$ Data = gethttpdata ($ login_interface_url); // Obtain the remote file content
$ Xml = simplexml_load_string ($ data );
$ Xmldata = var_export ($ xml, true );
// If var_dump () is used, it will be output directly, not what I want.



How can I read this xmldata?
How to obtain What are the values of each attribute in?
------ Solution --------------------
At the end of this post, xuzuning edited at 22:28:58 on. The default value is UTF-8.
$ String = <
  
   

1
1

XML;

$ Xml = simplexml_load_string ($ string); // xml without UTF-8 declaration can be accepted.
Foreach ($ xml-> foo as $ item ){
Foreach ($ item-> attributes () as $ a => $ B ){
Echo $ a, '= "', $ B," \ "\ n ";
}
}

But the result is still UTF-8
Name = "Jack"
Game = "lonely"
Name = "Jack"
Game = "lonely"

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.