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"