Page 1 of 1

fputcsv(): undefined function?

Posted: Tue May 24, 2005 3:00 pm
by fastTalker
I am trying to generate a CSV.

Using the example given on PHP.net: fputcsv() i get the following.

Code: Select all

Fatal error: Call to undefined function fputcsv()
In the notes on php.net people have posted their own definition of the funtion. Is fputcsv() just (what i guess you call) a constructor?

I am using PHP 5.04.

php.net's example:

Code: Select all

<?php

$list = array (
   'aaa,bbb,ccc,dddd',
   '123,456,789',
   '"aaa","bbb"'
);

$fp = fopen('file.csv', 'w');

foreach ($list as $line) {
   fputcsv($fp, split(',', $line));
}

fclose($fp);
?>

Posted: Wed May 25, 2005 4:08 pm
by thomas777neo
If a csv file is simply comma seperated.

You don't need to use the function, simply do this:

Code: Select all

<?php 
$list = array ('aaa,bbb,ccc,dddd','123,456,789','"aaa","bbb"'); 

$fp = fopen('file.csv', 'w+'); 

foreach ($list as $line) 
{   
    fwrite($fp,$line."\n");
} 

fclose($fp);
?>

Posted: Wed May 25, 2005 4:32 pm
by fastTalker
yeah, yeah. :wink:

Thanks, guess that was a pretty stupid question. :lol:

Any clue on why that function supposedly exists?

Posted: Wed May 25, 2005 4:43 pm
by thomas777neo
I don't know where the hell that function came from. I don't find it anywhere???

I thought that it might be a additional extension that you need. I don't know... :?: :?: :?: