fputcsv for PHP 4
Views Today: 3, Total Views: 6015, Submitted by: anjanesh on 13-09-2006
Even though fgetcsv() was introduced since PHP 3.0.8, fputcsv() was introduced only from PHP 5.1. It writes an array to a file in CSV format - readable by CSV Readers like MS Excel.
Heres a PHP 4 function that mimics PHP 5 fputcsv function.
Code
function fputcsv4($fh, $arr)
{
$csv = "";
while (list($key, $val) = each($arr))
{
$val = str_replace('"', '""', $val);
$csv .= '"'.$val.'",';
}
$csv = substr($csv, 0, -1);
$csv .= "\n";
if (!@fwrite($fh, $csv))
return FALSE;
}
Post A Comment
If you want to comment on this tutorial you must first register or login.



Syndicate