<bdo id='4uuwE'></bdo><ul id='4uuwE'></ul>

    1. <small id='4uuwE'></small><noframes id='4uuwE'>

      <tfoot id='4uuwE'></tfoot>
      <legend id='4uuwE'><style id='4uuwE'><dir id='4uuwE'><q id='4uuwE'></q></dir></style></legend>
      <i id='4uuwE'><tr id='4uuwE'><dt id='4uuwE'><q id='4uuwE'><span id='4uuwE'><b id='4uuwE'><form id='4uuwE'><ins id='4uuwE'></ins><ul id='4uuwE'></ul><sub id='4uuwE'></sub></form><legend id='4uuwE'></legend><bdo id='4uuwE'><pre id='4uuwE'><center id='4uuwE'></center></pre></bdo></b><th id='4uuwE'></th></span></q></dt></tr></i><div id='4uuwE'><tfoot id='4uuwE'></tfoot><dl id='4uuwE'><fieldset id='4uuwE'></fieldset></dl></div>

      1. 在分页期间保留 url 参数

        时间:2023-09-24

          <tbody id='MTkPa'></tbody>

        <tfoot id='MTkPa'></tfoot>

        <small id='MTkPa'></small><noframes id='MTkPa'>

          <i id='MTkPa'><tr id='MTkPa'><dt id='MTkPa'><q id='MTkPa'><span id='MTkPa'><b id='MTkPa'><form id='MTkPa'><ins id='MTkPa'></ins><ul id='MTkPa'></ul><sub id='MTkPa'></sub></form><legend id='MTkPa'></legend><bdo id='MTkPa'><pre id='MTkPa'><center id='MTkPa'></center></pre></bdo></b><th id='MTkPa'></th></span></q></dt></tr></i><div id='MTkPa'><tfoot id='MTkPa'></tfoot><dl id='MTkPa'><fieldset id='MTkPa'></fieldset></dl></div>
        1. <legend id='MTkPa'><style id='MTkPa'><dir id='MTkPa'><q id='MTkPa'></q></dir></style></legend>
          • <bdo id='MTkPa'></bdo><ul id='MTkPa'></ul>
                  本文介绍了在分页期间保留 url 参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有没有办法在分页时保留我的 GET 参数.

                  Is there any way to keep my GET parameters when paginating.

                  我的问题是我有几个不同的网址,即

                  My problem is that I have a few different urls i.e

                  questions.php?sort=votes&author_id=1&page=3
                  
                  index.php?sort=answers&style=question&page=4
                  

                  如何在我的分页类中创建一个指向页面的链接,该页面上有不同的页码,但仍保留 url 的其他部分?

                  How in my pagination class am I supposed to create a link to the page with a different page number on it but yet still keep the other parts of the url?

                  推荐答案

                  简而言之,您只需解析 URL,然后在末尾添加参数或替换它(如果它已经存在).

                  In short, you just parse the URL and then you add the parameter at the end or replace it if it already exists.

                  $parts = parse_url($url) + array('query' => array());
                  parse_str($parts['query'], $query);
                  $query['page'] = $page;
                  $parts['query'] = http_build_str($query);
                  $newUrl = http_build_url($parts);
                  

                  此示例代码需要 PHP HTTP 模块用于 http_build_urlhttp_build_str.后者可以用 http_build_query 替换,第一个 PHP 用户空间实现存在于如果您没有安装模块.

                  This example code requires the PHP HTTP module for http_build_url and http_build_str. The later can be replaced with http_build_query and for the first one a PHP userspace implementation exists in case you don't have the module installed.

                  另一种选择是使用 Net_URL2 包,它提供了一个各种 URL 操作的接口:

                  Another alternative is to use the Net_URL2 package which offers an interface to diverse URL operations:

                  $op = new Net_URL2($url);
                  $op->setQueryVariable('page', $page);
                  $newUrl = (string) $op;
                  

                  它更加灵活和富有表现力.

                  It's more flexible and expressive.

                  这篇关于在分页期间保留 url 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:PHP/MySQL 分页 下一篇:如何在 MySQL 中从给定的行号开始选择行?

                  相关文章

                  <small id='W7qDR'></small><noframes id='W7qDR'>

                    <i id='W7qDR'><tr id='W7qDR'><dt id='W7qDR'><q id='W7qDR'><span id='W7qDR'><b id='W7qDR'><form id='W7qDR'><ins id='W7qDR'></ins><ul id='W7qDR'></ul><sub id='W7qDR'></sub></form><legend id='W7qDR'></legend><bdo id='W7qDR'><pre id='W7qDR'><center id='W7qDR'></center></pre></bdo></b><th id='W7qDR'></th></span></q></dt></tr></i><div id='W7qDR'><tfoot id='W7qDR'></tfoot><dl id='W7qDR'><fieldset id='W7qDR'></fieldset></dl></div>
                    • <bdo id='W7qDR'></bdo><ul id='W7qDR'></ul>

                  1. <legend id='W7qDR'><style id='W7qDR'><dir id='W7qDR'><q id='W7qDR'></q></dir></style></legend>
                  2. <tfoot id='W7qDR'></tfoot>