#32987 [NEW]: PHP code ( fgetcsv() function )below do not working properly

From: Date: Mon, 09 May 2005 15:00:17 +0000
Subject: #32987 [NEW]: PHP code ( fgetcsv() function )below do not working properly
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-78811@lists.php.net to get a copy of this message
From:             max at tehnomir dot com dot ua
Operating system: Linux 2.4.29
PHP version:      4.3.10
PHP Bug Type:     Scripting Engine problem
Bug description:  PHP code ( fgetcsv() function )below do not working properly

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|


-- 
Edit bug report at http://bugs.php.net/?id=32987&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=32987&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=32987&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=32987&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=32987&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=32987&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=32987&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=32987&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=32987&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=32987&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=32987&r=notwrong
Not enough info:             http://bugs.php.net/fix.php?id=32987&r=notenoughinfo
Submitted twice:             http://bugs.php.net/fix.php?id=32987&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=32987&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=32987&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=32987&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=32987&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=32987&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=32987&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=32987&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=32987&r=mysqlcfg


Thread (4 messages)

« previous php.bugs (#78811) next »