<?php
if ($page > 1) {
  $pager .= '<a href="'.$url.($page - 1).'" class ="but_pg">←前の'.$perPage.'件</a> '.'<a href="'.$url.'1" class ="but_pg">Top</a>';
}

if ($page <= $delta) $alpha = $delta - $page + 1;
for ($i = $page - $delta; ($i <= $page + $delta + $alpha) && ($i <= $totalPage); $i++) {
  if ($i < 1) continue;
  if ($i == $page) {
    $preTag = '<div class ="but_pg">';
    $aftTag = '</div>  ';
  } else {
    $preTag = '<a href="'.$url.$i.'" class ="but_pg">';
    $aftTag = '</a>  ';
  }
  $links .= $preTag.$i.$aftTag;
}

$pager .= substr($links, 0, -2);
if ($page < $totalPage) {
  $pager .='<a href="'.$url.$totalPage.'" class ="but_pg">Last</a>'. '<a href="'.$url.($page + 1).'" class ="but_pg">次の'.$perPage.'件→</a>';
}

$op_pager = <<<EOD
<div id="border_box">
<div class="clearfix">
{$pager}
<div class ="but_pg">合計：{$num}件</div>
</div>
</div>
EOD;
print($op_pager);
?>
