Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php fputcsv在CSV中使用分号分隔符_Php_Arrays_Csv_Fputcsv - Fatal编程技术网

php fputcsv在CSV中使用分号分隔符

php fputcsv在CSV中使用分号分隔符,php,arrays,csv,fputcsv,Php,Arrays,Csv,Fputcsv,我编写了一个代码,从DB中检索数据,并使用函数“fputcsv”将其填充到CSV中 我把以下几点放在上面: $file = fopen("internal/customer_info.csv","w"); 然后检索数据并将其放入变量中,运行函数: $customerInfo = $first_name.";".$last_name.";".$address1.";".$address2.";".$postcode.";".$city.";".$country.";".$email; fputc

我编写了一个代码,从DB中检索数据,并使用函数“fputcsv”将其填充到CSV中

我把以下几点放在上面:

$file = fopen("internal/customer_info.csv","w");
然后检索数据并将其放入变量中,运行函数:

$customerInfo = $first_name.";".$last_name.";".$address1.";".$address2.";".$postcode.";".$city.";".$country.";".$email;
fputcsv($file,explode(';',$customerInfo));
最后,我关闭了文件

我的问题是: 如何使用分号分隔符?正如您所看到的,我在那里有分号,但CSV输出没有。它显示一个逗号


为什么?有人能帮我吗?

可以使用
fputcsv()的第三个参数设置分隔符。

int fputcsv(资源$handle,数组$fields[,string$delimiter=“,”[,string$enclosure=””,“[,string$escape\u char=“\”]”])

请更改:

fputcsv($file,explode(';',$customerInfo));
致:

fputcsv($file,explode(“;”,$customerInfo),“;”);
在询问堆栈溢出问题之前,请先检查。如果您使用
fputcsv()
执行了某些操作,您将无法得到您想要的。因此,请查看该函数的文档,特别是函数签名。非常感谢您的回答。您是对的,很抱歉我没有检查文档。祝您愉快 fputcsv($file,explode(';',$customerInfo), ";");