我正在尝试将旧的 vbscript 函数转换为 php 函数并运行我运行它,它似乎陷入了无限循环。这是脚本:
<?php
function pagination($str,$max_pg){
$pg = (int)$str;
$max_pg = (int)$max_pg;
if($max_pg <= 1){
exit();
}
$pstrout = '<table cellpadding="0" cellspacing="0" border="0">\r';
$pstrout .= '<tr class="f5">\r';
$pstrout .= '<td align="center" class="npagecounter" style="height:20px;color:#0000FF">\r';
if ($pg >= 2){
$pstrout .= '<a href="pg=1" id="Page1Link">« First</a> \r';
}
if (pg >=2){
$pstrout .= '<a href="pg='.($pg-1).'" id="Page'.($pg- 1).'Link">« Previous</a> \r';
}
if (max_pg > 5){
$npage_t = $pg + 4;
$npage_count_diff = $max_pg - $pg;
if ($npage_count_diff == 0){
$npage_count_diff2 = 4;
}elseif ($npage_count_diff == 1){
$npage_count_diff2 = 3;
}elseif ($npage_count_diff == 2){
$npage_count_diff2 = 2;
}else{
$npage_count_diff2 = 1;
}
if ($npage_t > $max_pg){
if ($npage_count_diff <= 3){
for ($ipages=$pg-$npage_count_diff2;$ipages=$max_pg;$ipages++){
if($ipages == $pg){
$pstrout .= '<span style="padding:2px 6px" class="fb">'.$ipages.'</span>';
}else{
$pstrout .= '<a href="?pg='.$ipages.'" id="Page'.$ipages.'Link">'.$ipages.'</a> ';
}
}
}else{
for ($ipages=$pg;$ipages=$max_pg;$ipages++){
if ($ipages == $pg){
$pstrout .= '<span style="padding:2px 6px" class="fb">'.$ipages.'</span>';
}else{
$pstrout .= '<a href="?pg='.$ipages.'" id="Page'.$ipages.'Link">'.$ipages.'</a> ';
}
}
}
}else{
if ($pg == 1){
for ($ipages=$pg;$ipages=($pg+4);$ipages++){
if ($ipages == $pg){
$pstrout .= '<span style="padding:2px 6px" class="fb">'.$ipages.'</span>';
}else{
$pstrout .= '<a href="?pg='.$ipages.'" id="Page'.$ipages.'Link">'.$ipages.'</a> ';
}
}
}elseif ($pg == 2){
for ($ipages=($pg-1);$ipages=($pg+3);$ipages++){
if ($ipages == $pg){
$pstrout .= '<span style="padding:2px 6px" class="fb">'.$ipages.'</span>';
}else{
$pstrout .= '<a href="?pg='.$ipages.'" id="Page'.$ipages.'Link">'.$ipages.'</a> ';
}
}
}else{
for ($ipages=($pg-2);$ipages=($pg+2);$ipages++){
if ($ipages == $pg){
$pstrout .= '<span style="padding:2px 6px" class="fb">'.$ipages.'</span>';
}else{
$pstrout .= '<a href="?pg='.$ipages.'" id="Page'.$ipages.'Link">'.$ipages.'</a> ';
}
}
}
}
}else{
for ($ipages=1;$ipages=$max_pg;$ipages++){
if ($ipages == $pg){
$pstrout .= '<span style="padding:2px 6px" class="fb">'.$ipages.'</span> ';
}else{
$pstrout .= '<a href="?pg='.$ipages.'" id="Page'.$ipages.'Link">'.$ipages.'</a> ';
}
}
}
if ($max_pg > 1){
if ($pg <> $max_pg){
$pstrout .= '<a href="?pg='.($pg+1).'" id="Page'.($pg+1).'Link">Next »</a> ';
}
}
if ($max_pg > 1){
if ($pg <> $max_pg){
$pstrout .= '<a href="?pg='.$max_pg.'" id="Page'.$max_pg.'Link">Last »</a>';
}
}
$pstrout .= '</td>\r';
$pstrout .= '</tr>\r';
$pstrout .= '<tr>\r';
$pstrout .= '</table>\r';
return $pstrout;
}
$current_page = 2;
$total_page = 24;
echo pagination($current_page,$total_page);
?>
我可能有一个支架不合适。请你帮我解决这个问题,无限循环。
非常感谢!