问题
I´m using a script to export Products from a shop to one .csv file. Now I need to change the header row to make it work for me.
I was searching a long time but didn't get it how to make it work. maybe I'm just to silly for that.
Lets say my CSV looks like this:
- Heading1 Heading2 Heading3
- value1 value2 value3
Now I need to open that csv file, change just the Headings, close and save it.
回答1:
$f = "file.csv";
$new_heading = "World,Mama,Euro";
$new_heading.="\n";
// read into array
$arr = file($f);
// edit first line
$arr[0] = $new_heading;
// write back to file
file_put_contents($f, implode($arr));
来源:https://stackoverflow.com/questions/22618065/how-to-edit-csv-header-row