1

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??!!

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.