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 (  => value1  => value2  => value3  => value4) ) this array has the name $a
Next I get the line by $b = $a[key1] and change it by the value $b = $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 )
I'm not very familiar with writing to CSV files but it seems that PHP.net has a good function to do this:
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
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)