Question

$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] => 
                )

        )

)

how do i access the object @attributes?

$nc_return->CommandResponse->DomainCheckResult->{'@attributes'} *// dont work*
Was it helpful?

Solution

use $object->attibuteName->attributes()->yourAttributeYouWant

straight from documentation http://www.php.net/manual/en/simplexmlelement.attributes.php

Example

<?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";
}
?>

Output

name="one"
game="lonely"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top