Re: php prog to generate .csv file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



What you need is only create a file with fwrite(), and write what you want 
to write. I give you "copy-paste" from PHP Manual with little change, that's 
'write file' [w] instead of 'append file' [a] on fopen()

<?php
$filename = 'test.txt';
$somecontent = "Add this to the file\n";

// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

   // In our example we're opening $filename in write mode.
   // The file pointer is at the first of the new file hence
   // that's where $somecontent will go when we fwrite() it.
   if (!$handle = fopen($filename, 'w')) {
        echo "Cannot open file ($filename)";
        exit;
   }

   // Write $somecontent to our opened file.
   if (fwrite($handle, $somecontent) === FALSE) {
       echo "Cannot write to file ($filename)";
       exit;
   }

   echo "Success, wrote ($somecontent) to file ($filename)";

   fclose($handle);

} else {
   echo "The file $filename is not writable";
}
?>

LuckyGuy354
IT Beginner

http://www.wiwid.org

----- Original Message ----- 
From: "Kirthi Sekhar Anupoju" <kirthia18@xxxxxxxxxxx>
To: <php-objects@xxxxxxxxxxxxxxx>
Sent: Wednesday, July 04, 2007 3:41 PM
Subject:  php prog to generate .csv file


> please lemme know if anyone has this prog...


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux