fputcsv(): undefined function?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fastTalker
Forum Newbie
Posts: 2
Joined: Tue May 24, 2005 2:47 pm

fputcsv(): undefined function?

Post 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);
?>
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Post 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);
?>
fastTalker
Forum Newbie
Posts: 2
Joined: Tue May 24, 2005 2:47 pm

Post by fastTalker »

yeah, yeah. :wink:

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

Any clue on why that function supposedly exists?
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Post 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... :?: :?: :?:
Post Reply