Jump to content


Photo

reading a file problem


  • Please log in to reply
3 replies to this topic

#1 slpwkr

slpwkr
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 13 March 2006 - 05:00 PM

is it possible to read a file starting from the bottom? thanx!

#2 Gast

Gast
  • Members
  • PipPipPip
  • Advanced Member
  • 131 posts
  • LocationSouth East England

Posted 13 March 2006 - 10:04 PM

[!--quoteo(post=354566:date=Mar 13 2006, 05:00 PM:name=slpwkr)--][div class=\'quotetop\']QUOTE(slpwkr @ Mar 13 2006, 05:00 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
is it possible to read a file starting from the bottom? thanx!
[/quote]

You could try this:

<?php
// Read entire file into variable
$file = file_get_contents("path/to/your/file.php");

// Split each line into a value of $lines array 
$lines = explode('\n', $file);

// Count the number of lines
$count = count($lines);

// Create empty variable
$temp = NULL;

// Read each line starting from the bottom into a variable
for($i=$count; $i==0; $i--) {
    $temp .= $lines[$i] . "<br />";
}

// Echo values
echo $temp;
?>

That code might need some ajusting... :)
OS and Internet Specs:
Windows XP (with SP2), 1680x1050, PHP 4, MySQL 3, Internet Explorer 6 &7 /FireFox 2.0/Opera 9.2

Tutorials:
Simple Introduction to AJAX and XMLHttpRequest
Creating Live Data with AJAX Making a Google Suggest like application

#3 Gast

Gast
  • Members
  • PipPipPip
  • Advanced Member
  • 131 posts
  • LocationSouth East England

Posted 13 March 2006 - 10:04 PM

[!--quoteo(post=354566:date=Mar 13 2006, 05:00 PM:name=slpwkr)--][div class=\'quotetop\']QUOTE(slpwkr @ Mar 13 2006, 05:00 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
is it possible to read a file starting from the bottom? thanx!
[/quote]

You could try this:

<?php
// Read entire file into variable
$file = file_get_contents("path/to/your/file.php");

// Split each line into a value of $lines array 
$lines = explode('\n', $file);

// Count the number of lines
$count = count($lines);

// Create empty variable
$temp = NULL;

// Read each line starting from the bottom into a variable
for($i=$count; $i==0; $i--) {
    $temp .= $lines[$i] . "<br />";
}

// Echo values
echo $temp;
?>

That code might need some ajusting... :)
OS and Internet Specs:
Windows XP (with SP2), 1680x1050, PHP 4, MySQL 3, Internet Explorer 6 &7 /FireFox 2.0/Opera 9.2

Tutorials:
Simple Introduction to AJAX and XMLHttpRequest
Creating Live Data with AJAX Making a Google Suggest like application

#4 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 13 March 2006 - 11:49 PM

Try this:

$filename = "path/to/file.txt";
$file = file($filename);
$file = array_reverse($file);





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users