5

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));

And finally, I closed the file.

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?

shieldcy
  • 559
  • 2
  • 8
  • 29
  • 2
    You do something with `fputcsv()`, your don't get what you want. So please look at the documentation of that function, especially at the function signature. – Rizier123 Aug 31 '15 at 10:52

1 Answers1

13

The delimiter can be set by using the third parameter of fputcsv():

int fputcsv ( resource $handle , array $fields [, string $delimiter = "," [, string $enclosure = '"' [, string $escape_char = "\" ]]] )

Please change:

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

to:

fputcsv($file,explode(';',$customerInfo), ";");

Please check the documentation before asking on Stack Overflow.

Rizier123
  • 56,111
  • 16
  • 85
  • 130
mario.klump
  • 2,848
  • 11
  • 19
  • 3
    Thanks a lot for the answer. You are right, sorry I didn't check the documentation. Have a nice day – shieldcy Aug 31 '15 at 10:58