$file = fopen("contacts.csv","w");
foreach(array_unique($matches[0]) as $email) {
fputcsv($file,explode(',',$email));
}
fclose($file);
The above code generates a CSV file. How can I update the CSV from the last recorded line without overwriting from the beginning?
Change "w"
to "a"
in the fopen
. It changes "write" into "append".
"append" opens the file and writes at the end of the file, not from the beginning like "write".
i.e. change this line
$file = fopen("contacts.csv","w");
to
$file = fopen("contacts.csv","a");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With