使用curl和php从url中读取xml数据 [英] Read xml data from url using curl and php

查看:116
本文介绍了使用curl和php从url中读取xml数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从网址读取XML资料。我有以下网址:

I want to read XML data from a URL. I have the url as follow

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);

有人可以告诉我如何读取xml数据吗?

Could anyone please tell me how to read xml data?

感谢.....

推荐答案

这里是一些示例代码(XML解析模块可能不可用您的PHP安装):

Here is some sample code (XML parsing module may not be available on your PHP installation):

<?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)

?>

现在,变量 $ xml 二维键值数组,你应该很容易找到如何从那里获取元素。

The variable $xml now is a multi-dimensional key value array and you should easily be able to figure out how to get the elements from there.

这篇关于使用curl和php从url中读取xml数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆