0

Driving me bonkers- I've got a simple XML element, and I just want to extract the '_Code' attribute. How would I do it?

<?php

$responseCode = "<STATUS _Condition='FAILURE' _Code='0705' _Description='Search failed subject not found' />";
$xml = simplexml_load_string($responseCode);

print_r($xml);

$code = $xml=>@attributes=>_Code; // Parse error
$code = $xml['@attributes']['_Code']; // Returns blank
echo "CODE = ".(string)$code; 

?>

CODE =

http://php.net/manual/en/function.simplexml-load-string.php

1 Answer 1

1

Use SimpleXMLElement::attributes()

$attrs = $xml->attributes();
$code = $attrs['_Code'];
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.