Questions tagged [fputcsv]

fputcsv is a PHP function that formats a line (passed as a fields array) as CSV and writes it (terminated by a newline) to the specified file handle. `fputcsv` support started with PHP version 5.1.0.

334 questions
41
votes
5 answers

Forcing fputcsv to Use Enclosure For *all* Fields

When I use fputcsv to write out a line to an open file handle, PHP will add an enclosing character to any column that it believes needs it, but will leave other columns without the enclosures. For example, you might end up with a line like…
Alan Storm
  • 157,413
  • 86
  • 367
  • 554
32
votes
8 answers

fputcsv and newline codes

I'm using fputcsv in PHP to output a comma-delimited file of a database query. When opening the file in gedit in Ubuntu, it looks correct - each record has a line break (no visible line break characters, but you can tell each record is separated,and…
EmmyS
  • 11,164
  • 41
  • 98
  • 147
27
votes
1 answer

Is there a library that can write an RFC 4180 CSV file with PHP?

I am aware of fputcsv, but according to this "wontfix" bug fputcsv does not correctly escape input, and its behavior will not be fixed for compatibility reasons. I would prefer an implementation that is compliant with RFC 4180 so Excel and…
AlexMax
  • 1,184
  • 13
  • 36
16
votes
2 answers

Avoid default quotes from csv file when using fputcsv

Avoid default quotes from csv using fputcsv fputcsv($fp, $array, ',', '"'); // OR fputcsv($fp, $array); In test.csv testname,045645765789,"""04.07.2012 12:10:52""" How to avoid above quotes here? Like below testname,045645765789,04.07.2012…
Justin John
  • 7,868
  • 14
  • 66
  • 123
15
votes
9 answers

fputcsv and integer typcasting to string

So I have a line that I want to do a fputcsv on that has some integers (that I need to be treated as strings but they are numbers). These integers have leading zeroes that get cut off when I do the fputcsv but I don't want that to occur, is there…
Ben Nelson
  • 6,704
  • 10
  • 44
  • 87
11
votes
1 answer

Adding BOM to CSV file using fputcsv

I have a simple CSV file being generated that includes foreign characters. I've noted that if I don't include a Byte Order Mark that the foreign characters aren't appearing properly in Excel (but they appear fine when a BOM is present). How can I…
Chuck Le Butt
  • 43,669
  • 58
  • 179
  • 268
9
votes
3 answers

php fputcsv and enclosing fields

I was just about to ask the same questions as the question aksed here.... Forcing fputcsv to Use Enclosure For *all* Fields The question was When I use fputcsv to write out a line to an open file handle, PHP will add an enclosing character to…
Lizard
  • 39,504
  • 36
  • 102
  • 164
8
votes
1 answer

fputcsv in PHP will not write to file

I've have searched and searched and done extensive debugging and for the life of me cannot figure out why fputcsv is not working for me. I can sucessfully open the .csv file and write to it. My debugging proves that the array is properly loaded…
user2149399
  • 81
  • 1
  • 1
  • 3
7
votes
3 answers

Skip Submit button in array_keys

I've got a PHP routine that processes a form and outputs the values to a CSV file. I'm using array_keys() to create the header row (skipped if there is one). Everything works perfectly except the final header term is "submit" because, of course, my…
Joe Lowery
  • 540
  • 9
  • 24
6
votes
3 answers

What kind of errors set "errno" to non-zero? Why does fopen() set "errno" while fputc() does not?

What kind of errors faced by what kind of library functions affect the errno and set it to non-zero value? In my following program, I intended to use if(errno!=0) as a condition to check if the library functions I used functioned properly or not,…
Rüppell's Vulture
  • 3,453
  • 7
  • 33
  • 47
5
votes
1 answer

How to use foreach in fputcsv?

I am trying to export woocommerce order details with a specific order status into a textfile. My problem is that it will only get details for one order because I am not using foreach. Does anyone know how I can change my code so it will get all…
Skurt
  • 89
  • 2
  • 9
5
votes
1 answer

php fputcsv use semicolon separator in 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…
shieldcy
  • 559
  • 2
  • 8
  • 29
5
votes
2 answers

Create CSV from multidimensional array with fputcsv

I'm trying to get a multidimensional array into a csv file. data in the array is as such: Array ( [0] => Array ( [product_id] => 1111 [name] => Alcatel One Touch Idol 2 [keyword] => alcatel-one-touch-idol-2 …
OniJoshin
  • 195
  • 1
  • 3
  • 19
5
votes
4 answers

Export whole table to CSV using laravel

I am new to laravel and having a tough time figuring out a way to export one table to csv. I have tried the following code in the controller class, but it gives me an error: public function get_export() { $table = Cpmreport::all(); $file…
Anuj
  • 53
  • 1
  • 1
  • 4
4
votes
1 answer

fputcsv() add quotes to every entry?

With this code I create my CSV export file: foreach ($data_for_export as $row) { $data = []; array_push($data, $row->product_id); array_push($data, $row->product_name); array_push($data, $row->product_code); array_push($data,…
Caner
  • 176
  • 1
  • 10
1
2 3
22 23