Rumah > Soal Jawab > teks badan
P粉0227236062023-08-23 15:46:59
Gunakan "n"
(用"
包裹)并使用"rn"
作为记录结束标记。如果单元格输入包含多行,则必须用"
keliling dalam nilai sel.
$fh = fopen('test1.csv', 'w+'); fwrite($fh, "sep=\t" . "\r\n"); fwrite($fh, 'A' ."\t" . 'B' . "\t" . 'C' . "\r\n"); fwrite($fh, 'D' ."\t" . "\"E\nF\nG\"" . "\t" . 'H' . "\r\n"); fclose($fh);
atau (menggunakan pembolehubah)
$varA = 'A'; $varB = 'B'; $varC = 'C'; $varD = 'D'; $varE = 'E'; $varF = 'F'; $varG = 'G'; $varH = 'H'; $fh = fopen('test2.csv', 'w+'); fwrite($fh, "sep=\t"."\r\n"); fwrite($fh, $varA . "\t" . $varB . "\t" . $varC . "\r\n"); fwrite($fh, $varD . "\t" . "\"$varE\n$varF\n$varG\"" . "\t" . $varH . "\r\n"); fclose($fh);
atau (gunakan fputcsv()
)
$fh = fopen('test3.csv', 'w+'); fwrite($fh, "sep=\t" . "\r\n"); fputcsv($fh, array('A', 'B', 'C'), "\t"); fputcsv($fh, array('D', "E\nF\nG", 'H'), "\t"); fclose($fh);
atau (menggunakan fputcsv()
dan pembolehubah)
$varA = 'A'; $varB = 'B'; $varC = 'C'; $varD = 'D'; $varE = 'E'; $varF = 'F'; $varG = 'G'; $varH = 'H'; $fh = fopen('test4.csv', 'w+'); fwrite($fh, "sep=\t" . "\r\n"); fputcsv($fh, array($varA, $varB, $varC), "\t"); fputcsv($fh, array($varD, "$varE\n$varF\n$varG", $varH), "\t"); fclose($fh);