php fputcsv在CSV中使用分号分隔符 [英] php fputcsv use semicolon separator in CSV
问题描述
我编写了一个代码,从数据库中检索数据,并使用"fputcsv"功能以CSV格式填充数据.
I wrote a code where I retrieve data from DB and populate them in CSV using the function 'fputcsv'
我将以下内容放在首位:
I put on top the following:
$file = fopen("internal/customer_info.csv","w");
然后我检索数据并将其放入变量中,运行函数:
Then I retrieve the data and put them in variables, run the function:
$customerInfo = $first_name.";".$last_name.";".$address1.";".$address2.";".$postcode.";".$city.";".$country.";".$email;
fputcsv($file,explode(';',$customerInfo));
最后,我关闭了文件.
我的问题是: 如何放置分号分隔符?如您所见,我在那里有分号,但是CSV输出没有.而是显示一个逗号.
My question is: How can I put a semicolon separator? As you can see I have semicolon there but the CSV output does not. It shows a comma instead.
那是为什么?谁能帮我吗?
Why's that? Can anyone help me?
推荐答案
可以使用fputcsv()
的第三个参数来设置定界符:
The delimiter can be set by using the third parameter of fputcsv()
:
int fputcsv(资源$ handle,数组$ fields [,字符串$ delimiter =," [,字符串$ enclosure =''[,字符串$ escape_char =" \]]] )
int fputcsv ( resource $handle , array $fields [, string $delimiter = "," [, string $enclosure = '"' [, string $escape_char = "\" ]]] )
请更改:
fputcsv($file,explode(';',$customerInfo));
收件人:
fputcsv($file,explode(';',$customerInfo), ";");
在询问堆栈溢出之前,请检查文档.
Please check the documentation before asking on Stack Overflow.
这篇关于php fputcsv在CSV中使用分号分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!