0

I have a file that has the following structure :

enter image description here

I'm trying to insert a new line at the end using this function :

ini_set('auto_detect_line_endings',true);//At the beginning of the php file
$handle = fopen("File.csv", "r+");
    $line = array(
        [0] => Trussville
        [1] => L01
        [2] => 8765
        [3] => this is , a sample (xx)
    );
    fputcsv($handle, $line, ',', '"'); 
    fclose($handle);

The result I get is as following : enter image description here

Can help me please ? Thanks

2
  • 1
    You'll need to jump to the end of the file after opening it using fseek() Commented Feb 10, 2015 at 19:31
  • Can you explain more please? Commented Feb 10, 2015 at 19:48

1 Answer 1

1

before writing, position the file pointer to the end of the file, like so:

...
fseek($handle, 0, SEEK_END);
fputcsv($handle, $line, ',', '"');
Sign up to request clarification or add additional context in comments.

1 Comment

You could also just open the file in append mode: $handle = fopen('file.csv', 'a');

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.