我正在创建一个逗号分隔的文件,它在每行的末尾附加加密字符,而不是在新行中开始下一行?
$inner_exported_header_array[] = 'ID';
$inner_exported_header_array[] = 'First Name';
$exported_customers_arr [] = $inner_exported_header_array;
foreach ($_list AS $row) {
$inner_exported_array = array();
$inner_exported_array[] = $row['id'];
$inner_exported_array[] = $row['v_first_name'];
$exported_customers_arr[] = $inner_exported_array;
}
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header('Content-Description: File Transfer');
header("Content-Type: text/plain");
header("Content-Disposition: attachment; filename=test.txt");
header("Pragma: no-cache");
header("Expires: 0");
outputCSV($exported_customers_arr);
function outputCSV($data) {
$outstream = fopen("php://output", "w");
function __outputCSV(&$vals, $key, $filehandler) {
fputcsv($filehandler, $vals); // add parameters if you want
}
array_walk($data, "__outputCSV", $outstream);
fclose($outstream);
}
输出显示:
"ID","First Name"[special character not copied here]1,Testname
但如果是:
"ID","First Name"
1,Testname
有没有想过,我们的新行应该在新行中,而不是在行尾插入特殊字符并从第一行结束的地方开始新行?