1

我会在这里得到一些帮助:

我想做的事:

从以下位置删除 &itemsperpage=10:

http://localhost/thi/search/filter.html?type=featured&page=2&itemsperpage=10

并从中创建一个链接:

http://localhost/thi/search/filter.html?type=featured&page=2&itemsperpage=15

到目前为止,这是我想出的:

<a href="<?php echo url::site(url::current()) . http_build_query($_GET) // don't know what follows ?>"

我正在使用的框架功能是:

url::current() = 以控制器/动作格式返回当前 url

url::site() = 返回绝对 url 即http://localhost/site/controller/action

所以我必须从 http_build_query 函数的结果字符串中删除 '&itemsperpage'

但我在字符编码等方面遇到了麻烦!请帮忙!

所以这是字符编码的问题:

$needle = '&itemsperpage';

        $querystring = http_build_query($_GET) . '<br/>';

        // echo $querystring . '<br/>';

        $pos = strpos($querystring, $needle);

        $remove = substr($querystring, ((int)$pos));

        echo substr(str_replace($remove, '', $querystring), 1); // returns ';'

我无法从 http_build_query 的结果中删除字符串 '&itemsperpage',即:'type=featured&page=2&itemsperpage=10' 和 strstr 之类的函数不输出任何内容

4

3 回答 3

5

我会这样做:

$array = $_GET;
$array['itemsperpage'] = 15;

然后只需使用您的代码,但使用新变量(和?):

<a href="<?php echo url::site(url::current()) . '?' . http_build_query($array)">
于 2009-12-03T03:30:37.627 回答
1

HttpQueryString类有几种获取、设置、修改查询字符串和“翻译”它们的字符集的方法。

于 2009-12-03T03:45:02.423 回答
1

您可以通过在构建查询字符串之前itemsperpage从数组中删除元素来实现您正在寻找的效果。$_GET

unset($_GET['itemsperpage']);

然后只需使用您已经编写的代码:

<a href="<?php echo url::site(url::current()) . http_build_query($_GET); ?>">

编辑:我误读了你的帖子。我以为您只想从 GET 请求中删除字段/值对。您所要做的就是用您想要的值覆盖该值:

$_GET['itemsperpage'] = 15;

然后使用您已经编写的代码。

于 2009-12-03T03:49:08.283 回答