Read xml data from url using curl and php
44,630
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);
?>
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.
Author by
user1403175
Updated on April 09, 2021Comments
-
user1403175 about 3 years
I want to read XML data from a URL. I have the URL as follows:
http://www.arrowcast.net/fids/mco/fids.asp?sort=city&city=&number=&airline=&adi=A
Here is my code:
$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);
Could anyone please tell me how to read xml data?