How to save the web content of the below link into an xml file? Below code is not working for me.
<?php
$url = "https://services.boatwizard.com/bridge/events/ae0324ff-e1a5-4a77-9783-f41248bfa975/boats?status=on";
copy($url, "file.xml");
?>
How to save the web content of the below link into an xml file? Below code is not working for me.
<?php
$url = "https://services.boatwizard.com/bridge/events/ae0324ff-e1a5-4a77-9783-f41248bfa975/boats?status=on";
copy($url, "file.xml");
?>
You can download the contents of the given link to file.xml via Curl:
<?php
$url = 'https://services.boatwizard.com/bridge/events/ae0324ff-e1a5-4a77-9783-f41248bfa975/boats?status=on';
$fp = fopen (dirname(__FILE__) . '/file.xml', 'w+');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);
?>
http://de2.php.net/manual/en/book.dom.php
$dom = new DOMDocument();
$dom->load('http://www.example.com');
$dom->save('filename.xml');
It can be done as follows:
function savefile($filename,$data){
$fh = fopen($filename, 'w') or die("can't open file");
fwrite($fh, $data);
fclose($fh);
}
$data = file_get_contents('your link');
savefile('file.xml',$data);
Use 2 functions file_get_contents() and file_put_contents();
file_get_contents - gets the content of file, A URL can be used as a filename with this function if the fopen wrappers have been enabled.
file_put_contents - put the contents of second argument to a file specified in first argument
<?php
$url = "https://services.boatwizard.com/bridge/events/ae0324ff-e1a5-4a77-9783-f41248bfa975/boats?status=on";
file_put_contents('file.xml',file_get_contents($url));
@chmod('file.xml', 0755);
?>