我想从URL读取XML数据.我有如下网址
http://www.arrowcast.net/fids/mco/fids.asp?sort=city&city=&number=&airline=&adi=A
这是我的代码
$Url="http://www.arrowcast.net/fids/mco/fids.asp?sort=city&city=&number=&airline=&adi=A";
if (!function_exists('curl_init')){
die('Sorry cURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $Url);
$output = curl_exec($ch);
$resultCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Close the cURL resource, and free system resources
curl_close($ch);
Run Code Online (Sandbox Code Playgroud)
谁能告诉我如何阅读xml数据?
谢谢.....
Kar*_*tik 11
以下是一些示例代码(PHP解析模块可能在您的PHP安装中不可用):
<?php
$url="http://www.arrowcast.net/fids/mco/fids.asp?sort=city&city=&number=&airline=&adi=A";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url); // get the url contents
$data = curl_exec($ch); // execute curl request
curl_close($ch);
$xml = simplexml_load_string($data);
print_r($xml)
?>
Run Code Online (Sandbox Code Playgroud)
变量$xml现在是一个多维键值数组,你应该能够很容易地弄清楚如何从那里获取元素.
| 归档时间: |
|
| 查看次数: |
38495 次 |
| 最近记录: |