我正在使用PHP开发应用程序。这里有一些示例代码。
$url = "http://localhost:8080/?Xml";
$xml = simplexml_load_file($url);
foreach($xml->result->doc as $doc){
echo "<pre>".print_r($doc)."</pre>";
}
其中一个项目看起来像我要求的那样。
SimpleXMLElement Object ( [@attributes] => Array ( [score] => 4.112774 [pos] => 0 ) [field] => Array ( [0] => http://www.w3schools.com/htmldom/dom_examples.asp [1] => text/html [2] => Free HTML XHTML CSS JavaScript jQuery XML DOM XSL XSLT RSS AJAX ASP .NET PHP SQL tutorials, references, examples for web building. [3] => html,css,tutorial,html5,dhtml,css3,xsl,xslt,xhtml,javascript [4] => www.w3schools.com [5] => en ) [snippet] => Array ( [0] => DOM Examples [1] => DOM HOME DOM Intro DOM Nodes DOM Node Tree DOM Methods DOM Node Access DOM Node Info DOM How To DOM Events DOM Summary DOM... ) )
我想知道如何访问数组项?
答案 0 :(得分:1)
foreach($doc->attributes() as $key => $value) {
echo "$key: $value\n";
}