1 回答
TA貢獻(xiàn)1803條經(jīng)驗(yàn) 獲得超6個(gè)贊
您的代碼看起來不錯(cuò),您只需要放在.csvline 上$temp_table = fopen('write.csv','w');,因?yàn)槟鷉putcsv()在 while 循環(huán)中使用函數(shù)。它基于 csv 文件標(biāo)準(zhǔn)生成輸出。如果您以.txt格式獲得輸出,則某些列會缺少引號""。在這種情況下,您需要手動(dòng)處理。
編輯
如果您不想將其輸出為 csv 而不是用以下更新的代碼替換您的代碼。
$table = fopen('read.csv','r');
$temp_table = fopen('write.txt','w');
while (($data = fgetcsv($table)) !== FALSE){
$data = '"'. implode('","', $data) .'"'; // this line will add the comma and double quote to each array value and wrap the string with double quote.
fputs($temp_table,$data);
}
fclose($table);
fclose($temp_table);
- 1 回答
- 0 關(guān)注
- 100 瀏覽
添加回答
舉報(bào)
