从PHP中的简单XML元素提取属性
我有一个简单的XML元素,我只想提取'\u Code'属性。我该怎么做从PHP中的简单XML元素提取属性,php,xml,Php,Xml,我有一个简单的XML元素,我只想提取'\u Code'属性。我该怎么做 <?php $responseCode = "<STATUS _Condition='FAILURE' _Code='0705' _Description='Search failed subject not found' />"; $xml = simplexml_load_string($responseCode); print_r($xml); $code = $xml=>@attribu
<?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;
?>
@attributes=>\u code;//解析错误
$code=$xml['@attributes'][''u code'];//返回空白
echo“CODE=”(字符串)$CODE;
?>
代码=
使用
$attrs = $xml->attributes();
$code = $attrs['_Code'];