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?
我想保存某个网站输出的xml的本地副本,每次我更改网站的URL以获取另一个xml副本时,它将覆盖从以前网站保存的文件,我该如何在php中执行此操作?
2 个解决方案
#1
$xml = file_get_contents('http://example.com/file.xml');
file_put_contents('file.xml', $xml);
#2
Thanks! Is there a problem using that script if the generated xml of the URL is so huge about 50MB?
谢谢!如果生成的URL的xml如此巨大,大约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;
}
#1
$xml = file_get_contents('http://example.com/file.xml');
file_put_contents('file.xml', $xml);
#2
Thanks! Is there a problem using that script if the generated xml of the URL is so huge about 50MB?
谢谢!如果生成的URL的xml如此巨大,大约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;
}