如何使用 PHP 读取/显示 XML [英] How to read/display XML using PHP
问题描述
有没有办法使用 PHP 从 [外部] xml(来自不同网站的 xml 文件)中读取数据?我知道有一种方法可以使用 JavaScript 读取 XML,但前提是它们都在同一个根中.
Is there a way to read off from an [external] xml (an xml file from a different website) using PHP? I know there's a way to read XML using JavaScript, but only if they are both in the same root.
您能否提供一个有关如何获取 xml 文件的示例,然后阅读以下内容:
Could you provide an example on how to source the xml file, then read the following:
<parent>
<child>
<grandchild>Example Text 1</grandchild>
</child>
<child>
<grandchild>Example Text 2</grandchild>
</child>
</parent>
谢谢!
推荐答案
SimpleXML 扩展提供了一个非常简单且易于使用的工具集,可以将 XML 转换为可以使用普通属性选择器和数组迭代器处理的对象.
The SimpleXML extension provides a very simple and easily usable toolset to convert XML to an object that can be processed with normal property selectors and array iterators.
http://us2.php.net/manual/en/simplexml.examples-basic.php
这篇关于如何使用 PHP 读取/显示 XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!