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
4
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
  • 111
  • 1
  • 10
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
  • 11,759
  • 36
  • 127
  • 221
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
  • 930
  • 5
  • 24
  • 47
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
  • 17,260
  • 14
  • 78
  • 95
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
  • 936
  • 1
  • 9
  • 30
3
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
  • 31
  • 1
  • 3
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
  • 63
  • 6
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
  • 91
  • 2
  • 10
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
  • 88
  • 1
  • 13
3
votes
3 answers

How to skip first row and read upto five rows from csv in PHP

How to skip first row and read upto five rows from csv in PHP Hello, I have following code in which I want to skip first row in csv that is headers of columns and read upto five rows of csv file. Current code skip first row but display all records.…
Nikita
  • 57
  • 1
  • 10
3
votes
2 answers

JSON Array Export to CSV in PHP

I'm trying to export to csv, a JSON with the following format: $json_file2{ "errors": { "code":0, "text":"" }, "results": { …
Juanjo
  • 43
  • 3
3
votes
2 answers

How to programatically HTTP POST a CSV file directly from an array in PHP?

I'm contributing data to the opencellid.org website. They have several API options to submit data but the only bulk method requires an HTTP POST file upload with the API key as a POST field. Formats acceptable are CSV, JSON and CLF3. I store the…
Peter Pudaite
  • 316
  • 5
  • 17
1
2
3
22 23