[SOLVED] Reading as text file backwards

This is a discussion on "[SOLVED] Reading as text file backwards" within the PHP Forum section. This forum, and the thread "[SOLVED] Reading as text file backwards are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Nov 8th, 2007, 10:14
Up'n'Coming Member
Join Date: Oct 2007
Location: london
Age: 25
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Reading as text file backwards

Hi everyone.

Im currently reading server log files from my server and taking the data into arrays. To make sure im getting the most relevant data im doing a time check to only get the latest hours data.

The only problem?? The file is HUGE, and the code scans the whole file before pulling the relevant data. Which is annoying considering the most recent data is at the bottom of the file!

So does anyone know of a way to read the file line by line but backwards??

Thanks again. Eon201
Reply With Quote

  #2 (permalink)  
Old Nov 8th, 2007, 10:19
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Reading as text file backwards

$this_array = array_reverse($this_array);

That will reverse the array...
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #3 (permalink)  
Old Nov 8th, 2007, 10:34
Up'n'Coming Member
Join Date: Oct 2007
Location: london
Age: 25
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Reading as text file backwards

ok thanks (again!) Rakuli.

So therefore I should take my code:
PHP: Select all

    if (file_exists($filename)) // Does the corresponding filename exist - if yes then
    
{
        
$fp fopen($filename"r"); //Open the server log
        
$content fread($fpfilesize($filename));     // Read the server log
        
        
$content explode("\n"$content); 
And implement your code by doing this?
PHP: Select all

    if (file_exists($filename)) // Does the corresponding filename exist - if yes then
    
{
        
$fp fopen($filename"r"); //Open the server log
        
$content fread($fpfilesize($filename));     // Read the server log
                 
$content  array_reverse($content );

        
$content explode("\n"$content); 
Thanks. Eon201
Reply With Quote
  #4 (permalink)  
Old Nov 8th, 2007, 10:38
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Reading as text file backwards

Not quite

You have it in the wrong order..

PHP: Select all

 if (file_exists($filename)) // Does the corresponding filename exist - if yes then

    
{
        
$fp fopen($filename"r"); //Open the server log
        
$content fread($fpfilesize($filename));     // Read the server log
                 // Create the array
        
$content explode("\n"$content);
        
// now reverse it
        
$content  array_reverse($content ); 
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #5 (permalink)  
Old Nov 8th, 2007, 10:53
Up'n'Coming Member
Join Date: Oct 2007
Location: london
Age: 25
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Reading as text file backwards

Thanks!!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] fread only reading 78 characters CloudedVision PHP Forum 2 Apr 7th, 2008 20:50
[SOLVED] Reading a remote XML source in JavaScript jonbritton JavaScript Forum 2 Jan 25th, 2008 13:01
reading a log file one line at a time depending on timestamp eon201 PHP Forum 1 Dec 4th, 2007 05:54
[SOLVED] Reading output. alexgeek PHP Forum 2 Oct 30th, 2007 00:41
Syntax error with Ajax file reading Paramiliar JavaScript Forum 0 Aug 12th, 2007 16:48


All times are GMT. The time now is 07:17.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43