reading a file line by line
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:
reading a file line by line
how do u i read a file line by line and not at once?
[i have in the past posted here a question about it,and found the url using the search but i get the message that the message dosent exist any more]
thnaks i advance
peleg
[i have in the past posted here a question about it,and found the url using the search but i get the message that the message dosent exist any more]
thnaks i advance
peleg
-
bladecatcher
- Forum Commoner
- Posts: 67
- Joined: Sat Mar 12, 2005 12:50 am
I'll try but be warned newbie lurks beneath.
Code: Select all
$wpage = fopen("www/myfile.txt", "r");
while(!feof($wpage)){
$readline = trim(fgetss($wpage, 1024)) ;
//do stufff
}
fclose($wpage);- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
anjanesh wrote:fgets()
php.net wrote:fgets -- Gets line from file pointer
php.net wrote:Reading ends when length - 1 bytes have been read, on a newline (which is included in the return value), or on EOF (whichever comes first).
Jcart wrote:I don't think there is any way of reading only up to a certain point of the file. The whole file must be put into memory first.
fgets() bro...
anjanesh had said that already, I was just replying to the person who pointed out file() and I was saying file() isn't anymore efficient then doing fgets(), and fgets() is more efficient in the case of a partial file.