note 84622 added to function.fgetcsv

From: Date: Tue, 22 Jul 2008 14:13:44 +0000
Subject: note 84622 added to function.fgetcsv
Groups: php.notes 
Request: Send a blank email to php-notes+get-142494@lists.php.net to get a copy of this message
Like pinkgothic at gmail dot com, 03-Apr-2007, I also found the documentation mildly misleading and also lacking a basic description. "The length parameter ... became optional in PHP 5" It IS required with PHP 4: array fgetcsv ( resource $handle , int $length [, string $delimiter [, string $enclosure [, string $escape ]]] ) fgetcsv is a specialized combination of fgets() and split() that reads a file and splits each record into an array based on $delimiter (default: comma) but ignoring any delimiters within $enclosure (default:double quotes) $fp1=fopen($inputfile,"r"); while(!feof($fp1)){ $record = fgetcsv($fp1,1000); // For example a csv record formatted as: // ,"Abels",,"Karen D.","123, Test blvd, Apt 7","Anytown","PA","19123-1234","610,644-1234",,,,,"""Harry""", // is stored as print_r($record); // (partially shown here) Array ( [0] => [1] => Abels [2] => [3] => Karen D. [4] => 123, Test blvd, Apt 7 ... [8] => 610,644-1234 ... [13] => "Harry" ) Any commas within a field were ignored and quotes within a field were handled correctly. ---- Server IP: 69.147.83.197 Probable Submitter: 71.185.239.53 ---- Manual Page -- http://www.php.net/manual/en/function.fgetcsv.php Edit -- https://master.php.net/note/edit/84622 Del: integrated -- https://master.php.net/note/delete/84622/integrated Del: useless -- https://master.php.net/note/delete/84622/useless Del: bad code -- https://master.php.net/note/delete/84622/bad+code Del: spam -- https://master.php.net/note/delete/84622/spam Del: non-english -- https://master.php.net/note/delete/84622/non-english Del: in docs -- https://master.php.net/note/delete/84622/in+docs Del: other reasons-- https://master.php.net/note/delete/84622 Reject -- https://master.php.net/note/reject/84622 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#142494) next »