分解 XML 文件
我有一个 XML 输出,它生成如下代码:
<loadavg>
<one>0.00</one>
<five>0.02</five>
<fifteen>0.02</fifteen>
</loadavg>
<!-- whostmgrd -->
我想知道如何使用 PHP 解析该文件,并获取
,<; 之间的内容。五>
和<十五>
。如果将其存储为 $loadavg[1]
数组,则会很有用。
谢谢
I've got an XML output that produces code such as:
<loadavg>
<one>0.00</one>
<five>0.02</five>
<fifteen>0.02</fifteen>
</loadavg>
<!-- whostmgrd -->
I would like to know how I can use PHP to parse that file, and grab the contents between <one>
,<five>
and <fifteen>
. It would be useful if it were to be stored as $loadavg[1]
an array.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的, SimpleXML 可以做到:
打印
Yep, SimpleXML can do it:
prints
解析 XML 文件的最简单方法是使用 SimpleXML。将 XML 作为 SimpleXML 对象加载并使用它获取数据应该很容易。如果您可以发布完整 XML 文件的示例,我可以提供一些示例代码。
The easiest way to parse an XML file is using SimpleXML. It should be easy to load the XML as a SimpleXML object and get the data using that. If you could post a sample of a complete XML file I could offer some sample code.