note 66909 added to function.fgetcsv

From: Date: Wed, 31 May 2006 22:52:34 +0000
Subject: note 66909 added to function.fgetcsv
Groups: php.notes 
Request: Send a blank email to php-notes+get-112683@lists.php.net to get a copy of this message
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 -- http://www.php.net/manual/en/function.fgetcsv.php Edit -- http://master.php.net/note/edit/66909 Del: integrated -- http://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://master.php.net/note/delete/66909/spam Del: non-english -- http://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://master.php.net/manage/user-notes.php

« previous php.notes (#112683) next »