FW: Bug #12643 [Com]: fgetcsv does some wrong things
| From: | Grant Walters | Date: | Wed, 21 Jul 2004 21:52:17 +0000 |
| Subject: | FW: Bug #12643 [Com]: fgetcsv does some wrong things | ||
| Groups: | php.mirrors | ||
| Request: | Send a blank email to php-mirrors+get-25488@lists.php.net to get a copy of this message | ||
Not sure what is going on here, but the <a href=http://an-classicpee-downl.da.ru>comic
erotic</a> comment is not good.
> -----Original Message-----
> From: PHP Bug Database [mailto:php-bugs@lists.php.net]
> Sent: Wednesday, 21 July 2004 03:13
> To: Grant.Walters@walters.co.nz
> Subject: Bug #12643 [Com]: fgetcsv does some wrong things
>
>
> ATTENTION! Do NOT reply to this email!
> To reply, use the web interface found at
> http://bugs.php.net/?id=12643&edit=2
>
>
> ID: 12643
> Comment by: comic-erotic1754 at hotmail dot com
> Reported By: Grant dot Walters at walters dot co dot nz
> Status: Bogus
> Bug Type: Filesystem function related
> Operating System: Linux
> PHP Version: 4.0.6
> New Comment:
>
> <a href=http://an-classicpee-downl.da.ru>comic
> erotic</a>
>
>
> Previous Comments:
> ------------------------------------------------------------------------
>
> [2002-06-18 17:49:03] Grant dot Walters at walters dot co dot nz
>
> So as my data that does not contain an "enclosure character", how
> should this be handled? The current manual page states that the
> parameter cannot be null.
>
> ------------------------------------------------------------------------
>
> [2002-06-18 08:14:35] hholzgra@php.net
>
> you mixed up delimiter and enclosure arguments here
> and redefined only the delimiter from ',' to '~'
>
> you also have to redefine the enclosure character
> to something you don't use in your data instead of
> '"' to make your code work (4th parameter to fgetcsv())
>
>
>
> ------------------------------------------------------------------------
>
> [2002-06-18 06:34:01] derick@php.net
>
> can you see if this is fixed in the latest non-stable cvs snapshot from
> snaps.php.net ?
>
> Derick
>
> ------------------------------------------------------------------------
>
> [2001-08-08 10:51:27] sniper@php.net
>
> Reproduced with latest CVS of PHP.
>
> --Jani
>
>
> ------------------------------------------------------------------------
>
> [2001-08-08 04:56:12] Grant dot Walters at walters dot co dot nz
>
> <?
>
> /*
> - fgetcsv when used with non " delimiter causes problems
> - script called from command line
> - on a large file (25,000 lines) the script will core dump most times
> with a segmentation fault
>
> Contents of gr
> DOS (CR/LF) or Unix (LF) record termination makes no difference to
> result
> ------------------------------------------
> 26261~~5402211~yes~MASTERFULL~0
> 26263~~0126003045~yes~"PIONEERING"~0
> 26263~~039300358~yes~ " CASSIOPEIA~0
> 26263~~91054745~yes~OLYMPIC~0
> 26261~~2302~yes~MASTERLESS~0
> 26263~~6003045~yes~PIONEERING~0
> ------------------------------------------
> */
>
> $file_name = "/tmp/unix/gr";
>
> // Faulty:
> echo "\nFAULTY\n";
> $text_file = fopen($file_name,"r");
> if ($text_file) {
> $count=1;
> while ($data=fgetcsv($text_file,200,"~")) {
> echo
> "Record:$count:".$data[0].":".$data[2].":".$data[4]."\n";
> $count++;
> }
> echo "$file_name Complete\n";
> }
> fclose($text_file);
>
> /*
> Problem 1: This will stop in the third record because of the unmatched
> "
> Problem 2: It strips the " characters out of the resultant array
> fields
> */
>
> //Working:
> echo "\nWORKING\n";
> $text_file = fopen($file_name,"r");
> if ($text_file) {
> $count=1;
> while ($data_in=fgets($text_file,200)) {
> $data=explode("~",$data_in);
> echo
> "Record:$count:".$data[0].":".$data[2].":".$data[4]."\n";
> $count++;
> }
> echo "$file_name Complete\n";
> }
> fclose($text_file);
>
> /*
> SCRIPT OUTPUT
>
> FAULTY
> Record:1:26261:5402211:MASTERFULL
> Record:2:26263:0126003045:PIONEERING
> /tmp/unix/gr Complete
>
> WORKING
> Record:1:26261:5402211:MASTERFULL
> Record:2:26263:0126003045:"PIONEERING"
> Record:3:26263:039300358: " CASSIOPEIA
> Record:4:26263:91054745:OLYMPIC
> Record:5:26261:2302:MASTERLESS
> Record:6:26263:6003045:PIONEERING
> /tmp/unix/gr Complete
>
> */
>
>
> ------------------------------------------------------------------------
>
>
>
>
Regards
Grant Walters
Brainbench 'Most Valuable Professional' for Unix Admin
Walters & Associates, P O Box 13-043 Johnsonville, Wellington, NEW ZEALAND
Telephone: +64 4 4765175 OR 4762661, CellPhone 025488265, ICQ# 23511989
"Never argue with an idiot. They drag you down to their level, then beat you with
experience."