php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34265 fgetcsv with length 0 work in other way than length specified
Submitted: 2005-08-26 08:53 UTC Modified: 2005-08-29 13:25 UTC
From: mdv at inyourpocket dot com Assigned:
Status: Closed Package: Strings related
PHP Version: 5.0.4 OS: Debian
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mdv at inyourpocket dot com
New email:
PHP Version: OS:

 

 [2005-08-26 08:53 UTC] mdv at inyourpocket dot com
Description:
------------
when length is 0 function parse strange

notice "[0] =>  X" (there is space before X in actual result) - hexa is 0x00

simple when getting same line:
fgetcsv($fd, 0, ';') != fgetcsv($fd, 4096, ';')

Reproduce code:
---------------
FILE (contains only 1 line for example):
"X";"Y";"Zv";"Text";"H";"S";"R";"n";"I";"Ob";"P";"Roz";"Pdj"

<?php
$fd = fopen('file', 'r');

$t = fgetcsv($fd, 0, ';');

echo '<pre>';
var_dump($t);
echo '</pre>';
?>


Expected result:
----------------
array(13) {
  [0]=>
  string(1) "X"
  [1]=>
  string(1) "Y"
  [2]=>
  string(2) "Zv"
  [3]=>
  string(4) "Text"
  [4]=>
  string(1) "H"
  [5]=>
  string(1) "S"
  [6]=>
  string(1) "R"
  [7]=>
  string(1) "n"
  [8]=>
  string(1) "I"
  [9]=>
  string(2) "Ob"
  [10]=>
  string(1) "P"
  [11]=>
  string(3) "Roz"
  [12]=>
  string(3) "Pdj"
}

Actual result:
--------------
array(13) {
  [0]=>
  string(2) " X"
  [1]=>
  string(1) "Y"
  [2]=>
  string(2) "Zv"
  [3]=>
  string(4) "Text"
  [4]=>
  string(1) "H"
  [5]=>
  string(1) "S"
  [6]=>
  string(1) "R"
  [7]=>
  string(1) "n"
  [8]=>
  string(1) "I"
  [9]=>
  string(2) "Ob"
  [10]=>
  string(1) "P"
  [11]=>
  string(3) "Roz"
  [12]=>
  string(3) "Pdj"
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-26 09:49 UTC] mdv at inyourpocket dot com
FILE (contains 1 line):
0;;;;0.00;0.00

<?php
$fd = fopen('file', 'r');
$t = fgetcsv($fd, 0, ';');
var_dump($t);
?>

returns:
array(1) {
  [0]=>
  string(1) "0"
}
array(2) {
  [0]=>
  string(0) ""
  [1]=>
  string(0) ""
}
array(2) {
  [0]=>
  string(0) ""
  [1]=>
  string(0) ""
}
array(2) {
  [0]=>
  string(0) ""
  [1]=>
  string(0) ""
}
array(2) {
  [0]=>
  string(0) ""
  [1]=>
  string(0) ""
}
array(1) {
  [0]=>
  string(1) "0"
}
array(1) {
  [0]=>
  string(1) "."
}
array(1) {
  [0]=>
  string(1) "0"
}
array(1) {
  [0]=>
  string(1) "0"
}
array(2) {
  [0]=>
  string(0) ""
  [1]=>
  string(0) ""
}
array(1) {
  [0]=>
  string(1) "0"
}
array(1) {
  [0]=>
  string(1) "."
}
array(1) {
  [0]=>
  string(1) "0"
}
array(1) {
  [0]=>
  string(1) "0"
}
array(1) {
  [0]=>
  string(0) ""
}
 [2005-08-26 16:34 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip


 [2005-08-29 09:33 UTC] mdv at inyourpocket dot com
5.1.0-dev OK
5.0.5-dev BAD
 [2005-08-29 13:25 UTC] sniper@php.net
Considered fixed then. (in PHP 5.1)

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 21:01:34 2025 UTC