Hey raza_ what are you doing? Lets see:
reading the entire file into an array; What does this function actually do?
your reading the entire file into an array. Guess what... on the OS level you just read character by character telling the OS to read the character by character till it hits the newline character increment the array number (or allocate new memory) then do the same thing over again. Then you are essenitally calling the sizeof() the array which tells you how much memory is allocated. Now, what you just did is something far different than what this guy wants. He wants something like fseek() that will actually take that file pointer that is used and move it N bytes in the file. The OS will gladly do this. Why does this way work? What essentially you are doing when you call fgets() as I said before it calls loops through fgetc() until a newline is hit. Well what does fgetc() do. Well if you cut through all the PHP and all the C... at the assembly level it calls an interrupt vector like:
int 21h (in dos)
What does this do? Well internally it does some stuff but when you exit (depends on architecture) it will send back an incremented variable (hex value) or in some systems you increment it yourself. So what you do when you call fseek() is essentially change the value of that register so that when the interrupt vector gets called again it reads from that byte or area in the file. Now, did this read the entire file in? No.. this just increments the fp to read some other byte in the file.
Your solution would work. But how would this cutdown on search time? You have to read in entire file to do this. So essentially it (in big O) O(N). Now using fseek() or something (which is what he was asking except he wanted one that new about lines). You can create algorithms that move the file pointer ahead to a specific location and read from there. Did you just read in the entire file? No. This is essentially what a database does. It uses complicatated hashing + B-Tree implementations to do figure out at the byte level how far it needs to seek to grab what it needs.
So that is a long explination, just to tell you I do know what I am talking about. If you would like to ignore me however, that is your buisness.
For more on this subject do a search on the internet, or mabye right some assembly language. 🙂