Jump to content

Displaying the first 1000 lines of a text file..


oz11

Recommended Posts

<?php
$file = 'information/information.txt';
$orig = file_get_contents($file);
$a = htmlentities($orig);
echo '<code>';
echo '<pre>';
echo $a;
echo '</pre>';
echo '</code>';
?>

I managed to get this code working, however I only want it to display the first "1000 lines" from the file.. how would i go about changing the code to do this? The idea behind the method is so that it takes users HTTP "logged" data and stores the to a text file, i only need the first 1000 lines.

 

Thanks.

Edited by oz11
cleaned code
Link to comment
Share on other sites

Nevermind..

 

found this:

$handle = popen("tail -50l 'information/information.txt' 2>&1", 'r');
echo '<pre>';
while(!feof($handle)) {
    $buffer = fgets($handle);
    echo "$buffer";
    ob_flush();
    flush();
}
echo '</pre>';
pclose($handle);

thanks and enjoi

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.