php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32987 PHP code ( fgetcsv() function )below do not working properly
Submitted: 2005-05-09 17:00 UTC Modified: 2005-05-22 20:11 UTC
From: max at tehnomir dot com dot ua Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 4.3.11 OS: Linux 2.4.29
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: max at tehnomir dot com dot ua
New email:
PHP Version: OS:

 

 [2005-05-09 17:00 UTC] max at tehnomir dot com dot ua
Description:
------------
Hello!

The fgetcsv() function do not working properly.
Below there is a fragment of the source data file. 

----------------source data file---------------

SZ | 7784252D00000  |  | 29.13
SZ | 7784265DA1000  |  | 21.23
SZ | 7784265DA10PG  | "Title ""V6"" | 17.9
SZ | 784270C20000   |  | 29.9
SZ | 784360E00000   |  | 29.41

---------------------end data file--------------

On big input files the function after line number 3 of data file need more and more memory and then crashes with trying to allocate memory.

Reproduce code:
---------------
#!/usr/bin/php
<?php

$delimiter = "|";

$data_file = fopen('price.txt','r') or die('Cannot open price.txt !');

while( !feof($data_file) ){

    $buffer = fgetcsv( $data_file, 1500, $delimiter );

    $buffer[0] = trim( $buffer[0] );
    $buffer[1] = trim( $buffer[1] );
    $buffer[2] = trim( $buffer[2] );
    $buffer[3] = trim( $buffer[3] );

    $tmp_file = fopen('./csv/'.$buffer[0].'.csv', 'a+');
    fwrite($tmp_file, $buffer[1] . $delimiter . $buffer[2] . $delimiter . $buffer[3]."\n" );
    fclose( $tmp_file );
}


Expected result:
----------------
7784252D00000||29.13
7784265DA1000||21.23
7784265DA10PG|Title "V6" | 17.9
784270C20000||29.9
784360E00000||29.41

Actual result:
--------------
7784252D00000||29.13
7784265DA1000||21.23
7784265DA10PG|Title "V6" | 17.9
SZ | 784270C20000   |  | 29.9
SZ | 784360E00000   |  | 29.41|


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-05-10 00:47 UTC] sniper@php.net
Thank you for taking the time to report a problem with PHP.
Unfortunately you are not using a current version of PHP -- 
the problem might already be fixed. Please download a new
PHP version from http://www.php.net/downloads.php

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.


 [2005-05-20 11:26 UTC] max at tehnomir dot com dot ua
This bug is also in new php 4.3.11
 [2005-05-22 20:11 UTC] max at tehnomir dot com dot ua
category changed: other function related
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 14:04:04 2025 UTC