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
0
votes
1 answer
How to get NULL values in csv for MySQL with fputcsv?
In PHP I'm using the fputcsv function to produce a comma separated file for import in a MySQL-table (using LOAD DATA INFILE) :
fputcsv($fcsv, array(
$id,
$name,
$optional
));
$optional can be empty so in MySQL this should be NULL
In…

Dylan
- 9,129
- 20
- 96
- 153
0
votes
1 answer
PHP, fputcsv, Want to write each array as a column not a row
Simple Example:
$a = array(1,2,3,4);
$b = array(10,20,30,40);
$c = array(100,200,300,400);
If I execute the following:
$fp = fopen('somefile.csv','w');
fputcsv($fp,$a);
fputcsv($fp,$b);
fputcsv($fp,$c);
fclose($fp);
I get a file that looks like…
user1676521
0
votes
2 answers
Creating CSV with PHP
I am attempting to create a dynamic csv file to export to a vendors site on my site. They want all values surrounded with double quotes. I am attempting to create the line then feed it to a fputcsv() but its coming out with a ton of double quotes…

Wally Kolcz
- 1,604
- 3
- 24
- 45
0
votes
2 answers
PHP - Export MySQL query to CSV Changeup
I see plenty of postings about the proper ways to export to CSV, and most developers recommend to use fputcsv()
How would I convert the script below to use fputcsv ?
You'll see I'm also exporting the Header row, which reflects the table column…

coffeemonitor
- 12,780
- 34
- 99
- 149
0
votes
2 answers
PHP checking if csv file exists?
The problem with this code is that each time I export from MySQL to csv it overwrites the already created csv. I want this code to check if there is an already created csv file -> create new one. Ex. (Sales-2012-9-8.csv) to…

Ali Hamra
- 232
- 1
- 8
- 18
0
votes
3 answers
How to pass values of variable to an array in PHP and save it to CSV file?
I am trying to generate a CSV file containing the name and email address from an form in an HTML file and using the PHP fputcsv function. But I am unable to pass the value of variables to the array and it is returning error message.
My PHP…

Gigacore
- 165
- 1
- 2
- 11
0
votes
2 answers
fputCSV strange behaviour
I am using fputcsv to create a csv but the data it outputs starts on the 3rd row when i open it in excel. Why is this?
I want to create a row of column headers using fputcsv, what is the best way to do this.?
public function indexAction()
{
…

RSM
- 14,540
- 34
- 97
- 144
0
votes
1 answer
outputting array to a csv
I am trying to output data from an array to a csv and download it.
I am using social engine which is built on zend framework.
public function indexAction()
{
$this->outputCSV();
//$this->view->navigation = $navigation =…

RSM
- 14,540
- 34
- 97
- 144
0
votes
3 answers
Php fputcsv trouble
I have a very basic question about fputcsv.
My goal is to create a csv file where for each row the first column is the key and the second the value.
The result of print_r on my table gives something like this
Array ( [city_name: London ] => 8000…

user1466622
- 25
- 4
0
votes
2 answers
PHP + XPath + fputcsv - Storing data in arrays
I'm parsing some HTML with DOM/Xpath, with the ultimate goal of generating a .CSV file with the data I've grabbed with my queries.
The current code below works, but only returns the last product name. I know I'm sort of on the right track here, but…

rocky
- 464
- 6
- 22
0
votes
1 answer
CSV generation Through Class giving result in just one Column
_helper->Csv() from an action controller
…

Edward Maya
- 429
- 2
- 10
- 25
-1
votes
1 answer
Why Export to CSV Data only showing in one column
We have many dynamic tables being generated in the process of our application. so we are trying to export the data from those dynamically generated table column data to .csv file.
$secondsql = "SELECT * FROM ".$reslt->dname." WHERE userid=:userid…

user1675571
- 11
- 2
-1
votes
1 answer
Use fputcsv but create many tables
If you have a single block of data, creating a table with fputcsv works great; it assumes the first row is a header and the following rows are of the same format.
But what do you do if you have multiple, differently formatted blocks of data you want…

Scott C Wilson
- 19,102
- 10
- 61
- 83
-1
votes
1 answer
How to keep trailing zeros in csv using php fputcsv?
I am using fputcsv function to write data in a file.But it is removing the trailing zeros from the output. Here is the code I am using
foreach($invoice_hdr_array as $csv_response)
{
fputcsv($fh1, $csv_response, ',', '"');
}
If you observe…

user3408779
- 981
- 2
- 19
- 43
-1
votes
1 answer
Export csv file from array (php) with fputcsv in commando line, not browser
i have write a code to export Data of an array to a csv file. But it only works, when i open the script in browser. I need a script that i can run in commando line because a cronjob. I can only show the last part of the script, the rest is for other…

Peter
- 11
- 5