Page 1 of 1

20 lines pagination

Posted: Sun Nov 09, 2008 5:24 am
by kkonline
Hi,
I am writing a script for displaying quotes. It reads froma txt file where quotes are delimited by \n

Now my requirement is to show 20 quotes i.e. 20 lines on each page how to paginate this?

Code: Select all

<?php
    $delim = "\n";
    $quotefile = "quotes.txt";
    // okay, let's get going. 
    $fp = fopen($quotefile, "r");
    $contents = fread($fp, filesize($quotefile)); 
    $quote_arr = explode($delim,$contents); 
    fclose($fp); 
   echo $quote_arr;
?>

Re: 20 lines pagination

Posted: Sun Nov 09, 2008 7:57 am
by Hannes2k
Hi,
you can read the file by using file(), so you get an array where each element is a line in your textfile.

After that, you have just to print the first, second, third... 20 entries from your array. For this, you can easily use a for loop.