语法错误,要么就是符号错了要么就是没有结束符号等。
array('Sortheast','a','b',93.26),array('Sorthwest','a','b',945.21),
第二括号错了。
我执行以后,因为没有CSV文件,所以没办法下去,有问题就追问吧
$sales=array(array('Northeast','a','b',12.54),array('Northwest','a','b',546.33),
array('Sortheast','a','b',93.26),array('Sorthwest','a','b',945.21),
array('All regions','--','--',1957.34));
$fh = fopen('sales.csv','w')or die("Can't open sales.csv");
foreach($sales as $sale_line){
if(fputcsv($fh,$sales_line)===false){
die("can't write CSV line");
}
}
fclose($fh) or die("can't close sales.csv");
?>
正确代码如下:
header("Content-type:text/html;charset=utf-8;");
$sales=array(array('Northeast','a','b',12.54),array('Northwest','a','b',546.33),
array('Sortheast','a','b',93.26),array('Sorthwest','a','b',945.21),
array('All regions','--','--',1957.34));
$arr=array();
$fh = fopen('sales.csv','w')or die("Can't open sales.csv");
foreach($sales as $sale_line){
if(fputcsv($fh,$sale_line)===false){
die("can't write CSV line");
}
}
fclose($fh) or die("can't close sales.csv");
?>