我需要读取php文件(表达式引擎)在传递url如/index.php/site/projects/
到php对象上生成的xml数据。(注意它不是一个物理文件)。我该怎么做呢?
由于我不太了解php的东西,请原谅我,如果我问了一些愚蠢的事情&
您可以使用simplexml_load_file(string $filename)来完成此操作。只需将完整的URL传递给该函数,例如:
$myXMLContent = simplexml_load_file('http://myserver.com/index.php/site/projects/');
如果需要使用此信息,请注意所有不重复的节点都可以直接使用:
$myXMLContent->nodename
那么所有属性都是节点数组的一部分,所以:
<nodename id="6" name="blabla"><subnode>Content</subnode></nodename>
可以被获取为:
echo $myXMLContent['id'];
echo $myXMLContent['name'];
echo $myXMLContent->subnode;
如果一次有很多子节点,可以使用:
echo $myXMLContent->subnode[2]
获取第三个子节点。
这是我能做的最好的帮助你,其余的可以找到:http://www.php.net/manual/fr/book.simplexml.php
也许您可以使用SimpleXML、DOMDocument类或cURL。
编辑:simplexml_load_file
文档中的示例<?php
// The file test.xml contains an XML document with a root element
// and at least an element /[root]/title.
if (file_exists('http://domain.com/index.php/site/projects/')) {
$xml = simplexml_load_file('http://domain.com/index.php/site/projects/');
print_r($xml);
} else {
exit('Failed to open the xml file.');
}
?>
我不是这方面的专家,但是在我链接到的页面上有很多很好的提示、例子和注释。