Hi there! I want to save a local copy of xml being ouput by a certain website, and everytime I changed the URL of a website to get another copy of xml it will overwrite the file that saved from previous website, how can I do this in php?
A:
$xml = file_get_contents('http://example.com/file.xml');
file_put_contents('file.xml', $xml);
cOle2
2009-05-30 03:23:29
Im sorry for that.. Actually the URL is not a xml file it is a php file that generates an xml file.http://example.com/generating_xml_file.phphow can i read the xml generated by that script and save that as an xml?
text
2009-06-01 01:15:55
Just replace the url with the one you want. There's nothing special about that code, it will simply save any url to 'file.xml'.
cOle2
2009-06-01 02:00:45
A:
Thanks! Is there a problem using that script if the generated xml of the URL is so huge about 50MB?
Here's my code please take a look tell me if it is okay.
$url = "http://projects.com/read.php";
$fp = fopen($url, 'r');
if ($fp) {
while (!feof($fp))
$buffer .= fgets($fp, 1024);
fclose($fp);
file_put_contents('file.xml', $buffer);
} else {
echo 'Could not connect to: ' . htmlentities($url) . '<br />';
echo 'Error #' . $err_num.': ' . $err_msg;
exit;
}
text
2009-06-01 02:36:58