Tuesday, July 23, 2013

Using CURL to get XML

if you have an IP restricted XML service you can put this script on the server to reflect the xml :


<?php
header("Content-type: text/xml");
function get_data($url) {
    $ch = curl_init();
    $timeout = 5;
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}
echo get_data("YOUR XML URL");
?>

No comments:

Post a Comment