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
2
votes
3 answers
PHP fputcsv outputting double records
I'm using this fputcsv code:
$result = mysql_query('SELECT * FROM `mash`');
if (!$result) die('Couldn\'t fetch records');
$fp = fopen('testCSV.csv', 'w');
if ($fp && $result) {
while ($row = mysql_fetch_array($result)) {
fputcsv($fp,…

benhowdle89
- 36,900
- 69
- 202
- 331
2
votes
1 answer
fputcsv putting quotes where it shouldn't
I'm writing a script to export products to Google Base... the problem is that when I use the following code in stock gets outputted as "in stock" and Google doesn't recognize that, it only recognizes it without the quotes. I don't know of a way to…

Ben
- 60,438
- 111
- 314
- 488
2
votes
3 answers
PHP fputcsv with UTF-8 Problem
I'm trying to allow my clients view some of the MySQL data in Excel. I have used PHP's fputcsv() function, like:
public function generate() {
setlocale(LC_ALL, 'ko_KR.UTF8');
$this->filename = date("YmdHis");
$create =…

user593171
- 23
- 1
- 3
2
votes
2 answers
fopen - failed to open stream: Permission denied
Is it possible to write data to CSV while the file is opened from desktop? Because I am trying to write some input data to CSV when user submit the form, but I am getting above error when the file is opened from my desktop. My system will only write…

Leon
- 329
- 2
- 3
- 15
2
votes
1 answer
File empty after fputcsv
I created a file with fputcsv
$handle = fopen('php://output', 'w+');
// Add the header of the CSV file
fputcsv($handle, array('Name', 'Surname', 'Age', 'Sex'), ';');
// Query data from database
// Add the data queried from…

monkeyUser
- 4,301
- 7
- 46
- 95
2
votes
1 answer
PHP fputcsv not Outputting First Row From SQL Query (Outputs all Other Rows After the First Row)
I am using the very simple code below to export a CSV of all of my MySQL table's data, "members". However, there is a total of 560 rows in the MySQL table, but the CSV only shows 559 of the MySQL table's rows (it does not display the very first…

Kelsey
- 913
- 3
- 19
- 41
2
votes
0 answers
Can not make fputcsv via ajax call
I am trying to output CSV file using another php file called from ajax from another page. Isn't that possible ? When I tried it didn't output CSV file. But via ajax response could see the proper values for CSV file spelled from the called page.…

Bineesh
- 494
- 1
- 5
- 18
2
votes
0 answers
fputcsv - insert columns under each other
Sorry for the title, but i didn´t know how to explain better. I´m exporting to a csv file two tables, but the final layout isn´t what i´m expecting, and i really don´t know how to perfom this, what i have right know is:
$sql = "SELECT a.number,…

Japa
- 632
- 7
- 30
2
votes
1 answer
fputcsv : separate values (fields) with ";" and remove "quote" enclosure
Thanks the community I was able to create a script that enable me to export data from a database table into a csv file.
"Article ID",Shoppergroupname,"Promotion Price",VAT-Code,"Article Currency","Promotion Start Date","Promotion End…

marcq
- 477
- 3
- 12
2
votes
2 answers
PHP | fputcsv : generated file only populated with field header, but no records
I can't figure out why this code only generate a file with the field headers, but no records.
File content :
"Article ID",Shoppergroupname,"Promotion Price",VAT-Code,"Article Currency","Promotion Start Date","Promotion End Date"
As you can see, no…

marcq
- 477
- 3
- 12
2
votes
2 answers
Remove lines from updating csv file
In my wamp server I have a script that updaing csv file every second.
I want to remove lines from the csv file, I have this code (from here: How To Delete The Top 100 Rows From a CSV File With PHP):
$input = explode("\n",…

jhon4
- 31
- 3
2
votes
2 answers
Help with exploding a name in PHP and writing back into a .CSV file
I wrote the code below to split up a fullname from a .csv file into a first name, middle name, and last name. It works well and gives the following kind of…

Thomas
- 1,571
- 3
- 12
- 12
2
votes
1 answer
php read write file not saving leading whitespace
I have a file about 2000 lines long that I am processing. It's a simple read, replace text and write back however, the leading whitespace is not being preserved.
Any ideas?

user3314053
- 239
- 1
- 3
- 11
2
votes
2 answers
PHP array to CSV issues
I have an array:
$rowcsv['reasonforabsence'] this contains an undetermined amount of values.
I want to output the values of this array to a CSV along with other values like this:
fputcsv($output, array( $overtime, $rowcsv['reasonforabsence']));
But…

Anthony Broadbent
- 393
- 2
- 15
2
votes
1 answer
fputcsv() not including comma in PHP
I am passing an array from Javascript to PHP using AJAX and attempting to write the array as a new line in a CSV file. This row is being appended correctly but isn't including the necessary closing "," at the end.
$row = $_POST['row'];
$handle =…
user4507841