Need help with my pager PHP function now that I use mod-rewrite

前端 未结 1 1249
执笔经年
执笔经年 2021-01-16 19:33

I am stuck now, here below is a snip from my paging code, this is the part the builds the URL for the paging links, it worked really great until now because now I am changi

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-16 20:29

    This will do the trick

    $uri = $_SERVER['REQUEST_URI'];
    $uri = preg_replace('#page/\d+/*#', '', $uri); // remove page from uri
    $uri = preg_replace('#/$#', '', $uri); // remove trailing slash
    
    $selfurl = $uri . '/page/';
    $page = $_GET['page'];
    if ($page) {
      $start = ($page - 1) * $items_per_page;
    } else {
      $start = 0;
    }
    if ($page == 0) {
      $page = 1;
    }
    

    What the code is doing here is removing the /page/2 part from the uri if it exists and then you can modify the code as you want.
    You mentioned that the code works if /page/1 part is not in the URI so removing that part if it exists should work too.

    0 讨论(0)
提交回复
热议问题