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.
Questions tagged [fputcsv]
354 questions
5
votes
1 answer
How to add lines to a CSV file without overwriting it
$file = fopen("contacts.csv","w");
foreach(array_unique($matches[0]) as $email) {
fputcsv($file,explode(',',$email));
}
fclose($file);
The above code generates a CSV file. How can I update the CSV from the last recorded line without overwriting…

troshan
- 134
- 1
- 11
4
votes
2 answers
PHP fputcsv producing empty files
I'm beginning work on a project that requires that I take multiple arrays and put them in a csv file. However, although it is generating the file, it is generally completely empty(0 b file size). Occasionally, if I miss something, it will put the…

LucenNox
- 41
- 1
- 3
4
votes
2 answers
php make csv file for the array
I have an array. When I am using print_r($output). I am getting the array like this
array(
[0] => Array
(
[listing_id] => 14
[category_id] => Modern Australian
[listing_name] =>…

NewUser
- 12,713
- 39
- 142
- 236
4
votes
1 answer
Currently my code exports data to a CSV file, and stores it on the server. But I want it to download the file. How do I do this?
I tried doing it with headers in the past, but it either downloaded an empty CSV file or the PHP file itself.

MTMaas
- 63
- 1
- 5
4
votes
2 answers
Remove first line in CSV and then save the file overwriting existing
I have a CSV file which is generated dynamically. I want to remove the first line of CSV and then save it again.
I have googled and was able to get first line of csv but the part of writing it again after removing is where I am stuck.
Here is…

Ahmar Ali
- 1,038
- 7
- 27
- 52
4
votes
3 answers
fputcsv prints result to screen instead into csv
I am trying to export database data into .csv via php. After a certain length of data it doesn't save the query into a .csv file but displays it on the screen. It looks like it's independent on which records are queried, and it also seems to be…

erdomester
- 11,789
- 32
- 132
- 234
4
votes
1 answer
4
votes
5 answers
Converting csv files data to an array using php str_getcsv function
I have string like which is created using fputcsv
Date,Name,Hours 2013-01-02,"Test User",7:59 2013-01-03,"Test User",7:53 2013-01-04,"Test User",8:12 2013-01-07,"Test User",7:56 2013-01-08,"Test User",8:25 2013-01-09,"Test User",7:56…

Subodh Ghulaxe
- 18,333
- 14
- 83
- 102
4
votes
3 answers
fputcsv - only one column
I want to save parts (and differently arranged) of my mysql database in a CSV file. For that I wrote this piece of code:
$headerDisplayed = false;
foreach ($arr as &$currName)
{
$result2 = mysql_query("SELECT * FROM Experiment Where…

Matthias
- 1,200
- 2
- 13
- 33
3
votes
1 answer
fputcsv only returning one row from array
This must be really simple... Following examples on here and php.net, I'm trying to get records from a mysql query, convert them to csv format, and assign this data to a variable for use in a program I have created. I would like to accomplish this…

Ben Glaser
- 33
- 4
3
votes
1 answer
How to write quotes ("") when using fputcsv of PHP
How can I write quotation marks ("") in csv files using fputcsv.
I tried:
'""' the result is written to csv file as """""""
"\"\"" The result is written to the csv file as \"\"

Soul
- 83
- 7
3
votes
2 answers
fputcsv displaying data in browser instead of downloading data as CSV file
I am using fputcsv function to export data as CSV file but it is displaying all data in browser instead of downloading this as CSV file. Here is my code
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment;…

wplearner
- 405
- 6
- 19
3
votes
1 answer
Generate CSV file on an external FTP server in PHP
I have some PHP code that successfully exports a MySQL table to a CSV file.
I would like to add to that code, so instead of saving locally the CSL file is exported to/saved on an external FTP server.
My current code:
//open database connection …

EllBrandon
- 103
- 2
- 11
3
votes
3 answers
How to Write Multiple Rows/Arrays to CSV File in one attempt using PHP?
I have to write multiple records in csv file. I'm using fputcsv function of php which take array as one row and write it in the file. In this way there will be multiple write operations for each row.
I'm looking for a method with which I can write…

DesiHacker
- 108
- 2
- 15
3
votes
1 answer
fputcsv Notice: Array to string conversion
I have a simple PHP code to save JSON to CSV , but I have an error, this the code:

Alvariko Zion
- 31
- 1
- 3