$page = 1;
$total = 20;
$prevs = $page - 4;
if($prevs <= 0) {
$prevs = 1;
}
$next = $page + 4;
if($next > $total) {
$next = $total;
}
for($i = $prevs; $i <= $page - 1; $i++) {
echo $i."\r\n";
}
echo '['.$page.']'."\r\n";
for($i = $page + 1; $i <= $next; $i++) {
echo $i."\r\n";
}