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
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
  • 1,960
  • 18
  • 24
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…
JELLEJ
  • 179
  • 1
  • 12
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,102
  • 6
  • 27
  • 59
3
votes
3 answers

fputcsv prints result to screen instead into csv

I am trying to export database data into .csv via php. After a certain length of data it doesn't save the query into a .csv file but displays it on the screen. It looks like it's independent on which records are queried, and it also seems to be…
erdomester
  • 11,491
  • 31
  • 126
  • 226
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,397
  • 7
  • 29
  • 41
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
  • 2,660
  • 5
  • 39
  • 67
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,550
  • 8
  • 32
  • 48
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
  • 446
  • 5
  • 15
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
  • 7
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
  • 34,076
  • 63
  • 192
  • 314
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
  • 34,076
  • 63
  • 192
  • 314
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…
Webnet
  • 55,814
  • 100
  • 278
  • 454
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
1 2
3
22 23