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
1
vote
1 answer

Unable to remove double quotes when using fputcsv

I've created a script that exports a bunch of MySQL tables to csv. Script works fine except I need to remove the double quotes before each row is thrown into the CSv file. I'm using str_replace which works when I need replace any instances of |.…
biggambino
  • 23
  • 1
  • 4
1
vote
1 answer

How to get data from an array and put it on txt file?

I did a json request to an API REST and got the following result: { respuesta:0, marcaciones:[ { codigo:18225611, codigoFicha:"18225611", rut:"18.225.611-0", nombres:"CAMILA ANDREA", …
Alex
  • 1
  • 5
1
vote
2 answers

Why does the character "x" change to "×" when placed into a .csv file after running my PHP script?

I wrote a PHP script that connects to a distributor's server, downloads several inventory files, and creates a massive .csv file to import into WooCommerce. Everything works except for one thing: when I look at the exported .csv file, the "x"…
1
vote
1 answer

PHP fputcsv unwanted additional last line

I have the following code which exports an array result to csv in PHP: $file = fopen('php://output', 'w'); $firstLineKeys = false; foreach ($result as $line) { if (empty($firstLineKeys)) { $firstLineKeys =…
Tashi
  • 477
  • 4
  • 12
1
vote
1 answer

Writing a hundred records to files

I want to write a hundred records continously in different files named with time(). This code works well but writes only 1 record to each file. How can I do this? $i=0; $file= time(); foreach ($dizi as $fields) { $i++; if($i%100==0){ …
Oaykol
  • 15
  • 3
1
vote
1 answer

Add 1 static line to a csv with fputcsv

I making a csv like this: $pulsos = json_decode(json_encode($pulsos), true); $f = fopen('php://output', 'w'); foreach ($pulsos as $line) { fputcsv($f, $line, ";"); } fclose($f); Where $pulsos is an Object. My csv is well generated, but I want…
pmiranda
  • 7,602
  • 14
  • 72
  • 155
1
vote
1 answer

LOAD DATA LOCAL INFILE from fputcsv: data not recorded

I have below CSV file: (3…
AnD
  • 3,060
  • 8
  • 35
  • 63
1
vote
0 answers

How to export from a html form to a csv file using PHP

Attempt #1: $title = $_POST['title']; $email = $_POST['email']; $description = $_POST['description']; $type = $_POST['type']; $content = $_POST['content2']; $fs = fopen("blogPosts.csv", "a"); fputcsv($fs,…
Alex Kyle
  • 23
  • 4
1
vote
1 answer

PHP fputcsv does not display Chinese Character Correctly

I need your help to finish my project. I take the data from my json files, some of which consist of chinese characters, but when I try to write to .csv it does not display properly. This is my code function writeCsv() { …
Faris Rayhan
  • 4,500
  • 1
  • 22
  • 19
1
vote
2 answers

php fputcsv of nested array.

Can someone please help me I have set of data which I'm sorting out by regular expression. I have correct result, but when I'm trying to call fputcsv, script is printing only fields without header which is IP and should be printed also. here is my…
Simon
  • 17
  • 1
  • 4
1
vote
1 answer

fputcsv() writing data separated with semicolon in separate cells

In my application I'm generating a csv file with some data using php. My code looks like shown below. $fileHandle = fopen('test.csv', "w"); $list = array ( array('aaa;cc;kk;', 'bbb', 'ccc', 'dddd'), array('123', '456', '789'), …
Jenz
  • 8,280
  • 7
  • 44
  • 77
1
vote
1 answer

Export multidimensional array of objects as CSV

I have an array $csvRows like the following. I want to export that array as CSV. Array ( [0] => SingleModule Object ( [module:SingleModule:private] => Module Object ( [name:Module:private]…
sumion
  • 137
  • 1
  • 2
  • 14
1
vote
2 answers

how to put a space after decimal value in csv using fputcsv?

This is the code i have used to write data into csv file. Everything is working fine except decimal values! $row[] = '14.31 '; fputcsv($fp, $row, ',', '"'); i have a space after .31 "14.31 " so length should be "6" and now i am getting "5". how…
Tobin Thomas
  • 106
  • 1
  • 2
  • 14
1
vote
2 answers

Write array to CSV file using PHP

I am trying to insert data into CSV file by storing data into array first before writing to CSV. But I am facing a problem with writing a multidimentional array to CSV file. Here is how my input looked like :
Emerald
  • 389
  • 1
  • 7
  • 18
1
vote
3 answers

Add heading on csv using fputcsv php

I'm trying to input some data into a csv file and it works nicely, but if I try to add the header of the table of data Excel won't let me open the file, because "the file format and extension of file.csv don't match. the file could be corrupted or…
Sefean
  • 591
  • 1
  • 7
  • 20