Coding, Programming & Algorithms, Tips, Tweaks & Hacks

fputcsv for PHP4

I found it strange why fgetcsv() was included since version 3.0.8 and fputcsv() only since 5.1.0RC1 when both are so closely interrelated. Heres fputcsv for ones not running on a minimum of PHP 5.1.0RC1.
if (!function_exists('fputcsv'))
Assuming includes functions that natively exist in PHP 5 and not in version 4.
function fputcsv($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;
The str_replace('"', '""', $val); is because Excel doesn't seem to understand \".
Vanakkam !


Anonymous said...

why does it output each line 12 times?!?!?!

Anonymous said...

If the point depend of either hand is 8 or 9, it's called a “natural” and no further playing cards are drawn. The drawing of a 3rd card, if needed, is dictated by strict rules depicted in the accompanying tables. There are two different bets called “pairs” and “tie.” On the “Pairs” wager, you are be} betting the first two playing cards on either the Banker or Player arms are a 메리트카지노 pair. On the “Tie” wager, you are be} betting that each the participant and banker arms will tie.