file read operation

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

Post Reply
jaymoore_299
Forum Contributor
Posts: 128
Joined: Wed May 11, 2005 6:40 pm
Contact:

file read operation

Post by jaymoore_299 »

How do you read a specific line from a file without putting the whole file into memory first than searching for that line?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

This does calssify into the "read the entire file into memory" but as alot of people still use fopen/fread functions to handle reading files, I thought I'd at least mention it.

If you use file() you read the file into an array and by using the keys you have the line numbers (starting at 0 tho). A personal favourite. Easier than fopen/fread and/or readfile():

Still not good enough?
Post Reply