【发布时间】:2018-03-21 16:32:49
【问题描述】:
我使用了这个脚本,但在 CSV 中写入了 1523 中的一些 01523 值。
$file = fopen('demosaved.csv', 'w');
// save the column headers
fputcsv($file, array('Column 1', 'Column 2', 'Column 3', 'Column 4', 'Column 5'));
// Sample data. This can be fetched from mysql too
$data = array(
array(01523, 'Data 12', 'Data 13', 'Data 14', 'Data 15')
);
// save each row of the data
foreach ($data as $row)
{
fputcsv($file, $row);
}
// Close the file
fclose($file);
在 1523 之类的 csv 输出中,我想要 01523。
我不想在值中使用 '/n', '/t' 和 '01523'。
另外如何在双引号中设置所有标题和值?比如“第 1 列”、“第 2 列”……
【问题讨论】:
-
用引号括起来/将其转换为字符串。另外,01523 是 php 中的八进制数,所以我很惊讶你得到 1523。
-
如果它没有用引号括起来 - 值将不是 01523。
-
如果它是用引号括起来,你将在你的CSV中得到01523。只是 Excel 去掉了前导零。在文本编辑器中查看。
-
是的。当我第一次在文本编辑器中打开时显示 0 但当我签入 excel 0 时不显示。