![](/img/trans.png)
[英]How to delete an element from an XML tree where attribute is specific string in Simple XML PHP
[英]Extract attribute from simple XML element in PHP
令人讨厌的是-我有一个简单的XML元素,我只想提取'_Code'属性。 我该怎么办?
<?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;
?>
代码=
使用SimpleXMLElement :: attributes()
$attrs = $xml->attributes();
$code = $attrs['_Code'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.