<?
$file = "news.txt";
$total = 10;

if (!is_file($file)) die();
if (!isset($_GET['page']) || $_GET['page'] == "" || !ctype_alnum($_GET['page'])) $page = "1";
else $page = $_GET['page'];

$data = array_reverse(file($file));
for ($x=0; $x<=count($data)-1; $x++) if ($page*$total > $x && ($page-1)*$total <= $x) echo "$data[$x]<BR>";

$do = ceil(count($data)/$total);
if ($page*$total-$total > "0") { $p = $page-1; echo "<A href='?page=$p'>Prev</A>&nbsp;"; }
for ($i=1 ;$i<=$do; $i++) echo ($i == $page) ? "<B>$i</B>&nbsp;" : "<A href='?page=$i'>$i</A>&nbsp;";
if ($page*$total+1 <= count($data)) { $p = $page+1; echo "&nbsp;<A href='?page=$p'>Next</A>"; }
?>
Published in: PHP
Download

Related snippets