Jump to content


Photo

Reading a Text File


  • Please log in to reply
1 reply to this topic

#1 R_P

R_P
  • Members
  • PipPipPip
  • Advanced Member
  • 98 posts

Posted 19 October 2006 - 07:22 PM

So I know how to get the contents of a text file, but I'm wondering if there is a way to retrieve only parts of the file without PHP reading the WHOLE thing. For instance:

I have a 50 MB text document. Thats pretty huge and using file() will take PHP a long time to parse it. Seeing as how all I want is the last 10 lines of the file, is there a way to open the text without parsing the whole document and retrieve the last 1o lines?
Pro in: Win2K3S | Apache2 | PHP5 | Perl5 | MySQL | MSSQL | Firefox | Photoshop
Student of: Ubuntu6 | Java | C | VB.NET | ASP.NET
Developer: Roddzilla Webstudios, Burrson CG, DVIDSHUB, The Four Nations
Student: Georgia Tech, Georgia Tech College of Computing

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 19 October 2006 - 10:14 PM

Use fseek() to position at a point, say 2K, from end of file and read from there.

Or file_get_contents() using the offset argument.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users