使用 simplexml 读取第一个值
我正在使用 simplexml 成功读取所有子节点。但是我如何读取“NumCrds”呢?
<ACCOUNT NumCrds="1">
<ACCNO>some Bank</ACCNO>
<CURRCODE>CAD</CURRCODE>
<ACCTYPE>00</ACCTYPE>
</ACCOUNT>
我在 PHP 手册的某个地方读过它,但现在找不到它。
$my_num_cards=$sxe->ACCOUNT['NumCrds'];
即使文件中存在诸如 2、3 之类的值,也会为所有记录打印数字 1。
I am using simplexml to read all the child nodes successfully. But how do I read the "NumCrds"?
<ACCOUNT NumCrds="1">
<ACCNO>some Bank</ACCNO>
<CURRCODE>CAD</CURRCODE>
<ACCTYPE>00</ACCTYPE>
</ACCOUNT>
I have read it somewhere in the PHP manual but I am unable to find it now.
$my_num_cards=$sxe->ACCOUNT['NumCrds'];
This is printing the number 1 for all the records even if there are values like 2, 3 in the file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可以使用数组索引访问属性:
也可以使用 SimpleXMLElement::attributes () 函数返回所有属性键/值对的列表。
Attributes can be accessed using array indexes:
It is also possible to use the SimpleXMLElement::attributes() function to returns a list of all of the attribute key/value pairs.
使用
$attrs = $el->attributes(); echo $attrs['NumCrds']
或只是echo $el['NumCrds']
。属性反映为数组元素,而子标签反映为对象属性。Use either
$attrs = $el->attributes(); echo $attrs['NumCrds']
or justecho $el['NumCrds']
. Attributes are reflected as array elements, while sub-tags are reflected as object properties.这就是我一直在寻找的。感谢您的帮助。
http://fr.php.net/manual/en/simplexmlelement.attributes .php#94433
This is what I was looking for. Thanks for all your help.
http://fr.php.net/manual/en/simplexmlelement.attributes.php#94433