List Info

Thread: note 66909 added to function.fgetcsv




note 66909 added to function.fgetcsv
user name
2006-05-31 22:52:34
Should you need it, here is a nice and simple function for
escaping csv fields properly.

This version is conditional - it only adds quotes if needed:
<?
function csv_escape($str) {
    $str = str_replace(array('"', ',',
"\n", "\r"),
array('""', ',', "\n",
"\r"), $str, &$count);
    if($count) {
        return '"' . $str . '"';
    } else {
        return $str;
    }
}
?>

This version is even simpler, but adds quotes even if not
needed.
<?
function csv_escape($str) {
    return = '"' .
str_replace('"','""', $str) .
'"';
}
?>
----
Server IP: 64.71.164.2
Probable Submitter: 71.199.123.24
----
X-Spam-Status: No, hits=3.1 required=5.0
tests=DATE_MISSING,FROM_NO_LOWER 
	autolearn=no version=2.64
----
Manual Page -- htt
p://www.php.net/manual/en/function.fgetcsv.php
Edit        -- http://master.p
hp.net/note/edit/66909
Del: integrated  -- ht
tp://master.php.net/note/delete/66909/integrated
Del: useless     -- http:
//master.php.net/note/delete/66909/useless
Del: bad code    -- http
://master.php.net/note/delete/66909/bad+code
Del: spam        -- http://m
aster.php.net/note/delete/66909/spam
Del: non-english -- h
ttp://master.php.net/note/delete/66909/non-english
Del: in docs     -- http:
//master.php.net/note/delete/66909/in+docs
Del: other reasons-- http://master
.php.net/note/delete/66909
Reject      -- http://master
.php.net/note/reject/66909
Search      -- http://ma
ster.php.net/manage/user-notes.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )