$nc_response = file_get_contents( $url );
$nc_return = simplexml_load_string($nc_response);
// return
SimpleXMLElement Object
(
[DomainCheckResult] => SimpleXMLElement Object
(
[@attributes] => Array
(
[Domain] => mydomain.com
[Available] => false
[ErrorNo] => 0
[Description] =>
)
)
)
如何访问对象 @attributes ?
$nc_return->CommandResponse->DomainCheckResult->{'@attributes'} *// dont work*
答案 0 :(得分:1)
使用 $object->attibuteName->attributes()->yourAttributeYouWant
直接来自文档http://www.php.net/manual/en/simplexmlelement.attributes.php
示例强>
<?php
$string = <<<XML
<a>
<foo name="one" game="lonely">1</foo>
</a>
XML;
$xml = simplexml_load_string($string);
foreach($xml->foo[0]->attributes() as $a => $b) {
echo $a,'="',$b,"\"\n";
}
?>
<强>输出强>
name="one"
game="lonely"