Dear All ,,
I would like to ask you a question related to reading files using php. How could I read a file from the end to the begin??
I tried to use file() function and doing reverse to the output array, this way does not make sense when the file size is too large,,
Is there any Ideas ???
Thanks alot
Reading file from the end to the begin
Moderator: General Moderators
Re: Reading file from the end to the begin
A good place to start is the file functions: http://php.net/manual/en/function.fopen.php
Re: Reading file from the end to the begin
Thanks Jade for reply,,Jade wrote:A good place to start is the file functions: http://php.net/manual/en/function.fopen.php
I did read this functions and related functions too,, I did not found such function that meet my objective
Re: Reading file from the end to the begin
I'm not sure how that couldn't meet your objective... you start by opening the file then getting all the contents, then closing the file.
Code: Select all
<?php
// get contents of a file into a string
$filename = "/usr/local/something.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
?>
Re: Reading file from the end to the begin
im not sure of a way to actually read the file from the end to the beginning... off hand im going to say you will have to read the whole file then reverse it. what are you trying to accomplish by reading it backwards?
Re: Reading file from the end to the begin
If you want to read it backwards you'll need to use a pointer: http://www.php.net/manual/en/function.fseek.php
Re: Reading file from the end to the begin
Thx Jade,, and sorry for being late to reply,,
I Just want to read file from the end since it contains the the last updated information that I need ,, ((business need))
any ways, I have heard about the pointer ,, I will read ur link ,,
You are really nice friend
thanks,,
I Just want to read file from the end since it contains the the last updated information that I need ,, ((business need))
any ways, I have heard about the pointer ,, I will read ur link ,,
You are really nice friend
thanks,,