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
1
vote
3 answers
fputcsv Creates the file but downloads it empty
I have this piece of PHP code that's intended to retrieve data from a mySQL database, and export it to a CSV file that has to be automatically downloaded after it was created.
$connection = mysqli_connect($host, $username, $password, $dbname) or…

med k
- 11
- 5
1
vote
1 answer
Add data into csv file properly using fputcsv()
I want to add curl data properly into csv file,
When I tried to add data into file data is added all over into csv file ..
I want to add it in only cell
Below is my code -

Nikita
- 57
- 1
- 10
1
vote
1 answer
Can't get PHP array to get into CSV via fputcsv()
I have an $events array that looks like
Array
(
[0] => Array
(
[4fe8a21c6f05d60023009d96] => any authentication
)
[1] => Array
(
[4fe8a21c6f05d60023009d96] => any authentication
)
…

Dhruv Ghulati
- 2,976
- 3
- 35
- 51
1
vote
2 answers
Can't write csv to .txt file? PHP
I am trying to use the putcsv function in php to write an array to a text file but the file is blank, I tried changing the extension to .csv and it works but I need to write it to .txt as per specifications of my assignment. I attempted to change…

James Dean
- 15
- 5
1
vote
0 answers
PHP fputcsv not appending all data in csv
I have this simple function to write data to csv, but not able to write all the data that I fetch.
Consider an example where I have 500 records to write to csv, which will correspond to 500 rows in csv. While I run this operation it sometimes write…

Leroy Mikenzi
- 792
- 6
- 22
- 46
1
vote
1 answer
fputcsv unexpected behavior
Take a look at this code example:
$store = array('This is something \" "special"!', 'Something else "special"!');
$ff = fopen('/tmp/aaaa.csv', 'w');
fputcsv($ff, $store);
fclose($ff);
It gives as a result this:
"This is something \"…

Darko Miletic
- 1,168
- 1
- 13
- 21
1
vote
0 answers
Excel sheet insertion not working correctly using fputcsv in php
I am trying to export into csv file. Here excel sheet insertion not correct. Only 3 rows inserted and it is not only in correct format also (some times 3 rows are inserted to one cell). Please help, what is the reason for that?
$row is a…

Rakhi Vijayan
- 593
- 1
- 7
- 12
1
vote
0 answers
Proper way to use PHP fputcsv function to export CSV file
What I want to do is, to export some dataset for Excel without using extra, 3rd party, heavy libraries.
The problem is, when I export the file, first row looks well, but starting from second row, it puts all $row data into first field of current…

heron
- 3,611
- 25
- 80
- 148
1
vote
1 answer
Unable to save data in each category - PHP CSV
I have a CSV file from which I want to insert data in the database.
There are some scenarios involved in it.
Like, If category exists in the database, the script simple insert all video of that category in the database without inserting the…

Keep Coding
- 636
- 9
- 26
1
vote
2 answers
why fputcsv produce extra blank column in csv
I am trying to remove unnecessary column from my csv. What i do is read from current csv and use fputcsv to produce a new one. However, the data is mess up because fputcsv add extra blank column just before $data[21]. Below is my code
$file_path =…

user1139747
- 67
- 1
- 2
- 9
1
vote
2 answers
Download file as csv when running script from command line
When I run my php script from a browser, I get a csv file to automatically download to the client using $fp = fopen('php://output', "w");, fputcsv and the appropriate header tags. It works very nicely.
When I run my script from the command line…

mikelovelyuk
- 4,042
- 9
- 49
- 95
1
vote
1 answer
How to export a tab-separated txt file from php array without quotes
I've managed to save a tab-separated file for a product feed with the code below. However, the feed that I am submitting requires that fields are not encased in quotes. Is there a way to save this file out without quotes in the…

Rob
- 50
- 1
- 1
- 10
1
vote
3 answers
2d array to fputcsv not working
My array looks like this;
Array
(
[0] => January
[1] => 2015-01-30
[2] => 2015-01-15
[3] => February
[4] => 2015-02-27
[5] => 2015-02-18
[6] => March
[7] => 2015-03-31
[8] => 2015-03-18
)
How can I output it to a csv in three columns? One…

mikelovelyuk
- 4,042
- 9
- 49
- 95
1
vote
1 answer
Use fputcsv create a .csv file and also update the page with table data
I am using fputcsv to create a .csv file and download it automatically for the user. This works great:
function create_csv($data, $not_valid, $csv_old_count, $file_name) {
header('Content-Type: text/csv; charset=utf-8');
…

Nic Hubbard
- 41,587
- 63
- 251
- 412
1
vote
2 answers
PHP - fputcsv: put JSON values retrieved from MySQL field in separate columns
I have a MySQL column that holds a JSON string of question numbers (0-165) as a key and question answers (score of 1-5) as a value. I need to retrieve all of the MySQL columns, put them into a .csv file with the JSON values in separate columns.
So…

chakeda
- 1,551
- 1
- 18
- 40