将文件导出为CSV时,字段" Sr. No
"的空格会在" Sr.
"的点后删除。我不希望删除该空间。代码如下:
$filename = "file.csv";
$fp = fopen('php://output', 'w');
$array = array('Sr. No.','Name','DOB','Address');
$header = str_replace(' ', '', $array);
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename='.$filename);
fputcsv($fp, $header);
$query = "select * from registratin";
$result = mssql_query($query);
$i = 1;
while($row = mssql_fetch_row($result)) {
$row = array_merge(array($i), $row);
fputcsv($fp, $row);
$i++;
}
答案 0 :(得分:1)
替换它:
$array = array('Sr. No.','Name','DOB','Address');
$header = str_replace(' ', '', $array);
有了这个:
$header = ['Sr. No.','Name','DOB','Address'];
我对为什么str_replace调用存在感到有点困惑。