Results 1 to 3 of 3

Thread: Edit a line in csv file

Hybrid View

  1. #1
    Join Date
    Sep 2013

    Question Edit a line in csv file


    How can I edit a specific line in my csv-file?

    my csv looks like this

    key1, value1, value2, value3, value4
    key2, value5, value6, value7, value8

    What I want is to edit the line with the specific key(for example key1). And I want to change value4 by value10.

    I was already trying to read the csv with this function:

    $a = array();
    $f = fopen("gebruikers.csv", 'r');
    while ($line = fgetcsv($f, 1000, ","))
    $key = array_shift($line);
    $a[$key] = $line;

    and so I get an array like this:

    Array ( [key1] => Array ( [0] => value1 [1] => value2 [2] => value3 [3] => value4) ) this array has the name $a

    Next I get the line by $b = $a[key1] and change it by the value $b[3] = $value10.
    after this I put it back in the big array $a[key1] = $b.

    Now the big array $a is edited correctly, but how do I write it back to my csv-file?

    (sorry for my english )

  2. #2
    Join Date
    Apr 2012
    I'm not very familiar with writing to CSV files but it seems that PHP.net has a good function to do this:


  3. #3
    Join Date
    May 2003
    Here is a class that deals with CSV files as an array of data and allows editing of the fields by a web form. I think it will do exactly what you are looking for:
    We do precision guesswork

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center