gpt4 book ai didi

php - 使用 simplexml_load_string 获取 xml 属性

转载 作者:可可西里 更新时间:2023-10-31 23:57:11 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Accessing @attribute from SimpleXML

我正在使用一些第三方 API,它们通过以下形式的 xml 返回错误:

<xml>
<status>0</status>
<error code="111">Error message text goes here.</error>
</xml>

使用 simplexml_load_string在 PHP 中,我可以轻松获得状态 0 和错误消息文本,但我找不到检索 code="111" 的方法。来自 <error code="111"> 的值.它似乎被 SimpleXML 删除了。

<?php
$bytesRead = file_get_contents('http://api.....');
$xml = simplexml_load_string($bytesRead);

echo '<pre>'; print_r($xml); echo '</pre>';
?>

输出

SimpleXMLElement Object
(
[status] => 0
[error] => Error message text goes here.
)

我错过了什么吗?有没有办法获得这个值,或者有人可以建议另一种方法来获得这个值?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com