2016-06-10 66 views
-1

我有一個PHP從一長串URL中獲取XML數據。看起來這是覆蓋xml.log文件,我怎樣才能將它附加到文件呢?PHP asXML寫入(追加)到文件

<?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'); 
} 

?> 

回答

2

考慮file_put_contents()一種保持FILE_APPEND標誌:

file_put_contents('xml.log', $xml->asXML(), FILE_APPEND); 

或者,使用與fopen()附加模式:

$fh = fopen('xml.log', 'a'); 
fwrite($fh, $xml->asXML()); 
fclose($fh);