<?php
function page($all_p,$page,$p_list,$url)
{
$maxpages = 3;
if ($all_p <= $page || $page < 1) $page = 1;
$pages = $all_p / $p_list;
$pages = ceil($pages);
if ($pages > 1)
{
if ($page > 1) echo '<a href="'.$url.'page='.($page-1).'" accesskey="1">'.htmlspecialchars("<<<[1]").'</a>';
else echo htmlspecialchars("<<<[1]");
echo ' ';
if ($page < $pages) echo '<a href="'.$url.'page='.($page+1).'" accesskey="3">'.htmlspecialchars("[3]>>>").'</a><br/>';
else echo htmlspecialchars("[3]>>>").'<br/>';
if ($page == 3) echo '<a href="'.$url.'page=1">1</a>';
if ($page > 3) echo '<a href="'.$url.'page=1">1</a>...';
$l = $page - floor($maxpages / 2);
$r = $page + floor($maxpages / 2);
if ($l < 1)
{
$l = 1;
$r = $maxpages;
}
if (($page - 1) >= $maxpages && $page != $pages)
{
$ll = $l;
echo '<a href="'.$url.'page='.$ll.'">&#171;</a> ';
}
for ($l; $l <= $r; $l ++)
{
if ($l > $pages) break;
if ($l == $page) print "<b>$page</b>";
else echo ' <a href="'.$url.'page='.$l.'">'.$l.'</a> ';
}
if ($pages - 1 > $r)
{
$ll = $r + 1;
echo '<a href="'.$url.'page='.$ll.'">&#187;</a> ';
}
if ($page <= $pages - 2 && $pages > 3) echo '...<a href="'.$url.'page='.$pages.'">'.$pages.'</a>';

}
}
?>