You are here: Re: PHP read large file line by line? « PHP Programming Language « IT news, forums, messages
Re: PHP read large file line by line?

Posted by Pedro Graca on 10/13/06 18:17

[ Please don't top-post. Read http://www.caliburn.nl/topposting.html ]

ZabMilenko top-posted (corrected):
> howa wrote:
>> hi,
>>
>> how to read a large php file line by line?
>>
>> fread can't?
>>
>> thanks.
>>
>
> $file_array = file($file_name);
>
> foreach ($file_array as $line_number => $line)
> {
> // Handle the line
> }
>
>
>
> See: http://us3.php.net/manual/en/function.file.php

What if the file is larger than memory_limit (8Mb)?

http://www.php.net/manual/en/ini.core.php#ini.memory-limit

fgets() is the right answer in this case.

So, instead of coding with file() which works now with a 200K file,
start with fgets and your script will not break when the file grows.

http://www.php.net/fgets

--
File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация