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.

354 questions
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
  • 4
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
  • 406
  • 8
  • 18
3
votes
2 answers

PHP - Array to CSV by Column

issue: I have an associative array, where all the keys represent the csv headers and the values in each $key => array.. represent the items in that column. Research: To my knowledge, fputcsv likes to go in row by row, but this column-based array is…
amurrell
  • 2,383
  • 22
  • 26
3
votes
2 answers

Unwanted new line string / fputcsv

So I am trying to use fputcsv, and it works, almost like it is intented. I have this weird problem, that I can not seem to solve, and I do not find any good documentation or even people who have this problem. When there is a string that is being put…
JJ15
  • 201
  • 2
  • 16
3
votes
3 answers

Export MySQL data to .csv using PHP

I'm exporting data to a .csv file and it's working perfectly but I have one small issue. I fetch name and gender from a table but for gender I save id in my database (i.e., 1 = Male, 2 = Female). My below code gives me id for gender, how can I fix…
Arif
  • 1,222
  • 6
  • 29
  • 60
3
votes
3 answers

Blank line at the beginning when writing a csv file in php

I'm trying to write a csv file from an array, as a header of a csv file $csv_fields[] = 'produto_quest'; $csv_fields[] = 'produto_quest1'; $csv_fields[] = 'comentario_aspecto_atm'; $csv_fields[] = 'aspecto_geral_int'; $csv_fields[] =…
RBrazao
  • 49
  • 1
  • 6
3
votes
1 answer

Getting this PHP error: fputcsv() expects parameter 2 to be array

I am trying to insert an array into an array of arrays using array_splice. array_splice($array, 0, 0, $fieldNames); The resulting array is then converted to csv format with fputcsv. I get the following error: fputcsv() expects parameter 2 to be…
Rynardt
  • 5,547
  • 7
  • 31
  • 43
3
votes
4 answers

fputcsv Inserting HTML code into a csv file

I have problem with writing csv file using fputcsv. Its putting the page html also into the csv file. Whats wrong with my code ? //Excel header header("Content-Disposition: attachment; filename=\"Delivery_Reports.csv\";" ); header("Content-type:…
3
votes
1 answer

File permissions for fopen in write mode - PHP

I have a PHP script that writes some rows to a CSV file: $fp = fopen($csv, 'w'); I'm using mode 'w' so that it will create the file if it doesn't exist, however the file is automatically given 644 permissions even though I gave 777 to the whole…
AlxVallejo
  • 3,066
  • 6
  • 50
  • 74
3
votes
3 answers

fputcsv doesn't write any data in a CSV file

In my web site I'm creating a table from the mysql data and then now I want to add a export button buttom of the table so that a user will be able to download the data as an CSV file. To do that I wrote dummy form:
CanCeylan
  • 2,890
  • 8
  • 41
  • 51
2
votes
1 answer

Concurrent File Writes PHP

I have a project with a paranoid client... He is worried the site is going to crash if more than 200 people are using the site at the same time. Does my script look like it will collect the data okay? Or will the file give users…
PaulELI
  • 444
  • 6
  • 16
2
votes
2 answers

How to remove specific lines from a csv file in php?

I have a csv file like this: I would like to delete the first 3 lines as well as the line 'Data as of' to have only my table of values. I tried array_shift($csv_data); but it only removes the first line, how can I do it ?
Patrick62
  • 71
  • 8
2
votes
3 answers

How to export a multi dimensional array to a specific .csv layout with fputcsv PHP

I know the answer to this will be obvious but I have spent the last 3 days trying to figure it out. I am having trouble getting a Multi-Dimensional array to export into the correct layout in the exported .csv file. I seem to able to either get all…
Biwwabong
  • 27
  • 1
  • 7
2
votes
1 answer

Change mysql column names for use with FPutCSV()

$result = mysql_query("show columns from mash"); for ($i = 0; $i < mysql_num_rows($result); $i++) { $colArray[$i] = mysql_fetch_assoc($result); $fieldArray[$i] = $colArray[$i]['Field']; } fputcsv($fp,$fieldArray); to grab mysql column names…
benhowdle89
  • 36,900
  • 69
  • 202
  • 331
1 2
3
23 24