I have a file name checklist.csv
I try to insert a new information in this file using php
My method work and i can insert a new information in the file
But i have a problem that the new information is near the past information
Example
,92,electrical,Final As built drawing,,,,,,,,,,,,,,,,,,,,,93,electrical,test,,,,,,,,,,,,,,,,,,,,
But what i want is to look like this in the file:
,92,electrical,Final As built drawing,,,,,,,,,,,,,,,,,,,,
,93,electrical,test,,,,,,,,,,,,,,,,,,,,
This is the code i use
$number=secure($_POST['txt_number'],"num");
$category=secure($_POST['txt_category'],"text");
$desc=secure($_POST['txt_desc'],"ibtext");
$file = fopen('checklist.csv', 'a+');
$csv=array();
$csv[]="";
$csv[]=$number;
$csv[]=$category;
$csv[]=$desc;
$csv[]="";
$csv[]="";
$csv[]="";
$csv[]="";
$csv[]="";
$csv[]="";
$csv[]="";
$csv[]="";
$csv[]="";
$csv[]="";
$csv[]="";
$csv[]="";
$csv[]="";
$csv[]="";
$csv[]="";
$csv[]="";
$csv[]="";
$csv[]="";
$csv[]="";
$csv[]="";
fputcsv($file,$csv);
fclose($file);
How I add the new information in a new line??!!
I expect that you are opening the CSV file on Windows.
Windows only shows a new line for \r\n
whereas Linux shows a new line for \n
.
See fputcsv and newline codes for someone else who has had a similar issue.