20 lines pagination

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

20 lines pagination

Post 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;
?>
Hannes2k
Forum Contributor
Posts: 102
Joined: Fri Oct 24, 2008 12:22 pm

Re: 20 lines pagination

Post 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.
Post Reply