|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-05-10 00:47 UTC] sniper@php.net
[2005-05-20 11:26 UTC] max at tehnomir dot com dot ua
[2005-05-22 20:11 UTC] max at tehnomir dot com dot ua
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 30 04:00:01 2025 UTC |
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|