|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2001-08-03 12:45 UTC] brianm at dealnews dot com
Ok, I can live with the embedded newlines in fgetcsv even though I think it is wrong. No other app will read a csv file this way. MySQL for example exports a literal \n for newlines and translates them on import rather than embedding them.
But, I do think the length should be respected no matter what:
data:
-----------------
6,7,8,line1
1,2,3,"line2
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
2,4,5,line3
script:
---------------
$fp=fopen("test.csv", "r");
while($line=fgetcsv($fp, 24)){
print_r($line);
}
Nothing after that quote gets read. Even after 24 bites have been read.
It would seem to me that the code which reads an additional line if an embedded newline is reached should not issue an FP_FGETS with len but should use len-strlen(temp). This would make the length param make more sense. And then if len was met it should terminate the record and start all over.
The code in this function is less that understandable with all the great names like buff and temp floating around. I tried looking at it but will leave it to the guys who wrote it.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 23 19:00:01 2025 UTC |
This example of yours actually crashes with current HEAD.. (gdb) bt #0 0x4192fdc9 in memchr () from /lib/libc.so.6 #1 0x8559784 in ?? () at md4.c:255 #2 0x41922fa6 in _IO_getline (fp=0x855dd58, buf=0x8559784 "", n=23, delim=10, extract_delim=1) at iogetline.c:39 #3 0x419227a0 in _IO_fgets (buf=0x8559784 "", n=24, fp=0x855dd58) at iofgets.c:48 #4 0x82450bd in php_stdiop_gets (stream=0x855e894, buf=0x8559784 "", size=24) at /usr/src/web/php/php4/main/streams.c:696 #5 0x8243e34 in _php_stream_gets (stream=0x855e894, buf=0x8559784 "", maxlen=24) at /usr/src/web/php/php4/main/streams.c:248 #6 0x81cb335 in zif_fgetcsv (ht=2, return_value=0x855e2ac, this_ptr=0x0, return_value_used=1) at /usr/src/web/php/php4/ext/standard/file.c:2070 #7 0x82828b7 in execute (op_array=0x85596fc) at /usr/src/web/php/php4/Zend/zend_execute.c:1587 #8 0x826fbc4 in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /usr/src/web/php/php4/Zend/zend.c:810 #9 0x8239951 in php_execute_script (primary_file=0xbffff95c) at /usr/src/web/php/php4/main/main.c:1388 #10 0x8288e07 in main (argc=2, argv=0xbffff9c4) at /usr/src/web/php/php4/sapi/cli/php_cli.c:674 #11 0x418e89cb in __libc_start_main (main=0x828829c <main>, argc=2, argv=0xbffff9c4, init=0x8086d78 <_init>, fini=0x82fed04 <_fini>, rtld_fini=0x4000aea0 <_dl_fini>, stack_end=0xbffff9bc) at ../sysdeps/generic/libc-start.c:92