php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26600 only one line CSV
Submitted: 2003-12-12 05:56 UTC Modified: 2003-12-12 09:29 UTC
From: dozoyousan at mail dot goo dot ne dot jp Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 4.3.4 OS: Win2k,Linux
Private report: No CVE-ID: None
 [2003-12-12 05:56 UTC] dozoyousan at mail dot goo dot ne dot jp
Description:
------------
If only one line csv file , fgetcsv read two or more lines.

Reproduce code:
---------------
<?
	$file_name = "temp.csv";
	
	$file_ptr = fopen($file_name, "w");
	fwrite( $file_ptr, "php, pear, pecl");
	fclose( $file_ptr );
	
	$file_ptr = fopen( $file_name, "r" );

	while( $rows = fgetcsv( $file_ptr , filesize( $file_name ), "," ) )
		echo nl2br( print_r( $rows, true ));
	
	fclose( $file_ptr );
?>

Expected result:
----------------
Array
(
[0] => php
[1] => pear
[2] => pecl
)


Actual result:
--------------
Array
(
[0] => php
[1] => pear
[2] => pec
)
Array
(
[0] => l
)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-12-12 09:30 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You need to use filesize() + 1 because the last byte is reserved for (\0).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 17 17:01:27 2024 UTC