如何编辑.csv标头行 [英] How to edit .csv header row
本文介绍了如何编辑.csv标头行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用脚本将产品从商店导出到一个.csv文件.现在,我需要更改标题行以使其对我有用.
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.
可以说我的CSV看起来像这样:
Lets say my CSV looks like this:
- Heading1 Heading2 Heading3
- value1 value2 value3
现在我需要打开该csv文件,仅更改标题,然后关闭并保存.
Now I need to open that csv file, change just the Headings, close and save it.
推荐答案
$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));
这篇关于如何编辑.csv标头行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文