PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
pelegk2
Forum Regular
Posts: 633 Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:
Post
by pelegk2 » Mon Jul 05, 2004 8:27 am
and not asa whole stirng?
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Mon Jul 05, 2004 8:40 am
Code: Select all
$lines ='0';
if ($fh = fopen('textfile.txt','r')) {
while (!feof($fh)) {
if (fgets($fh,1048576)) {
$lines++;
}
}
}
print $lines;
That do the trick ?
launchcode
Forum Contributor
Posts: 401 Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:
Post
by launchcode » Mon Jul 05, 2004 8:44 am
Is there a specific reason to need to read it line by line? because it takes a lot longer to do. Why not just read it into a string and then split it - or into an array and loop through it?
m3mn0n
PHP Evangelist
Posts: 3548 Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada
Post
by m3mn0n » Mon Jul 05, 2004 9:22 am
file_get_contents()
then explode() by \n or \r\n
foreach() through it all to display it
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Mon Jul 05, 2004 9:23 am
It's quite easy actually, just call
and $file_contents will be an array with each element containing a line of the file.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
pelegk2
Forum Regular
Posts: 633 Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:
Post
by pelegk2 » Tue Jul 06, 2004 2:31 am
thnaks all of u
i have used file()
so simple to use
and YEs launchcode there is a reason to read each line by line
launchcode
Forum Contributor
Posts: 401 Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:
Post
by launchcode » Tue Jul 06, 2004 2:38 am
Ok just wondered - because file() doesn't read it line-by-line at all