【发布时间】:2015-04-16 19:23:42
【问题描述】:
我有一个类似http://somedomain.com/frieventexport.php 的网址,如果我查看该网站的源代码,该网址的内容是一个普通的 XML 结构:
如何解析这个 URL 并在 PHP 中使用它? 这个脚本给了我一个错误……“加载 XML 时出错”。
<?php
$xml_url = "http://somedomain.com/frieventexport.php";
if (($response_xml_data = file_get_contents($xml_url))===false){
echo "Error fetching XML\n";
} else {
libxml_use_internal_errors(true);
$data = simplexml_load_string($response_xml_data);
if (!$data) {
echo "Error loading XML\n";
foreach(libxml_get_errors() as $error) {
echo "\t", $error->message;
}
} else {
print_r($data);
}
}
?>
【问题讨论】:
-
$response_xml_data 变量中是否有任何数据?有时在 file_get_contents 中不允许读取 URL。请检查您的 ini 设置。