note 66908 added to function.fgetcsv

From: Date: Wed, 31 May 2006 22:44:33 +0000
Subject: note 66908 added to function.fgetcsv
Groups: php.notes 
Request: Send a blank email to php-notes+get-112682@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('"', ','), array('""', ','), $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/66908 Del: integrated -- http://master.php.net/note/delete/66908/integrated Del: useless -- http://master.php.net/note/delete/66908/useless Del: bad code -- http://master.php.net/note/delete/66908/bad+code Del: spam -- http://master.php.net/note/delete/66908/spam Del: non-english -- http://master.php.net/note/delete/66908/non-english Del: in docs -- http://master.php.net/note/delete/66908/in+docs Del: other reasons-- http://master.php.net/note/delete/66908 Reject -- http://master.php.net/note/reject/66908 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#112682) next »