我有一个PHP,它从一长串URL中获取XML数据。看来这是覆盖了xml.log文件,我怎样才能将它附加到文件中?
<?php
include("connect.php");
$query = "SELECT * FROM urls_list";
$result = mysqli_query($conn, $query) or die("MySQL Error..." . mysqli_error($conn));
while ($row = mysqli_fetch_array($result))
{
$url = $row['url'];
$xml = simplexml_load_file($url);
echo $xml->asXML('xml.log');
}
?>
答案 0 :(得分:2)
考虑保留FILE_APPEND
标志的file_put_contents():
file_put_contents('xml.log', $xml->asXML(), FILE_APPEND);
或者,使用附加模式的fopen():
$fh = fopen('xml.log', 'a');
fwrite($fh, $xml->asXML());
fclose($fh);