早睡早起,方能养生
Sleep early rise early, way to keep healthy

PHP写入csv文件

super
2023-12-12 18:31
views 755

PHP写入csv文件:

 

 

方式一:

 

$filename = 'data.csv';
$file2 = fopen('./' . $filename, 'w');

fputcsv($file2, ['666', '777', '888']);
fputcsv($file2, ['111', '222', '333']);

fclose($file2);

 

方式二:

 

手动组装CSV格式(每个行数据使用英文逗号分隔,并且手动添加换行符)

 

$filename = 'data.csv';
$file2 = fopen('./' . $filename, 'w');

fwrite($file2, implode(',', ['666', '777', '888']) . "\n");
fwrite($file2, implode(',', ['111', '222', '333']) . "\n");

fclose($file2);

 



分享
20 条讨论
top