Url参数保存到变量并在分页链接中重用它

时间:2011-11-15 21:46:38

标签: php url get

我有这个网址: http://localhost:8080/projects/mnhh/trunk/ee2/index.php/search?data%5Bcategories%5D%5B1%5D%5B%5D=11&data%5Bcategories%5D%5B2%5D%5B%5D=47&data%5Bcategories%5D%5B3%5D%5B%5D=3

这将返回我分页的结果。我想获取参数并将它们附加到分页链接,以便在页面之间导航时保​​持搜索结果。

提前致谢

2 个答案:

答案 0 :(得分:0)

$categories = $_GET['data']['categories'];
foreach($categories as $array) {
    foreach($array as $category) {
        echo $category."<br/>";
    }
}

根据您的评论如下:

$categories = $_GET['data']['categories'];
foreach($categories as $array) {
    foreach($array as $category) {
        $category = intval($category); // anty-injection, we assumed $category is a number
        echo '<a href="domain.com?'.$category.'">Category #'.$category.'</a><br/>';
    }
}

答案 1 :(得分:0)

经过大量搜索,我发现了这个函数http_build_query(),这正是我想要的:)