读取带有(at)符号的PHP XML对象


Read PHP XML object with (at) sign

$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*

use $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"