Add a new line to a CSV file

前端 未结 4 1546
心在旅途
心在旅途 2020-12-24 04:57

If I have a CSV saved on a server, how can I use PHP to write a given line, say 142,fred,elephants to the bottom of it?

4条回答
  •  别那么骄傲
    2020-12-24 05:24

    Open the CSV file for appending (fopen­Docs):

    $handle = fopen("test.csv", "a");
    

    Then add your line (fputcsv­Docs):

    fputcsv($handle, $line); # $line is an array of strings (array|string[])
    

    Then close the handle (fclose­Docs):

    fclose($handle);
    

    I hope this is helpful.

提交回复
热议问题