You are here: Re: Read first 10 lines from a file « All PHP « IT news, forums, messages
Re: Read first 10 lines from a file

Posted by Peter van Schie on 10/10/07 11:24

Erwin Moller wrote:

> Hi,
>
> Look at the function name file() at www.php.net.
> It reads lines into an array.
> Take the first 10...

If the file is big, it's not very efficient to read the whole file into
an array, using file().

I'd suggest using something like:

<?php

if (($hFile = fopen("file.txt", "r")))
{
for ($iLine = 0; $iLine < 10; $iLine++)
{
$strLine = fgets($hFile);
// do something with $strLine
//
}
}
else
{
// error handling
//
}
?>

Peter.

--
http://www.phpforums.nl

 

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

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