1

我有这种类型的网址:

http://mysite.com/results.php?location=montreal&car-rental=no&add-hotel=no&moods%5B%5D=Adventure&moods%5B%5D=Arts&moods%5B%5D=Culture&moods%5B%5D=Well-being&moods%5B%5D=Zen&weather-dependent=yes

在 PHP 中,仅获取部分的最佳方法是$_GET[]什么?

例如:

$get = location=montreal&car-rental=no&add-hotel=no&moods%5B%5D=Adventure&moods%5B%5D=Arts&moods%5B%5D=Culture&moods%5B%5D=Well-being&moods%5B%5D=Zen&weather-dependent=yes

谢谢。

4

2 回答 2

4

您是否正在搜索类似的内容:

$_SERVER['QUERY_STRING']
于 2013-09-13T19:08:23.913 回答
2

我想你正在寻找这个:

$str = 'http://mysite.com/results.php?location=montreal&car-rental=no&add-hotel=no&moods%5B%5D=Adventure&moods%5B%5D=Arts&moods%5B%5D=Culture&moods%5B%5D=Well-being&moods%5B%5D=Zen&weather-dependent=yes';

$query = parse_url($str, PHP_URL_QUERY);
parse_str($query, $arr);
print_r($arr);

/*
Array
(
    [location] => montreal
    [car-rental] => no
    [add-hotel] => no
    [moods] => Array
        (
            [0] => Adventure
            [1] => Arts
            [2] => Culture
            [3] => Well-being
            [4] => Zen
        )

    [weather-dependent] => yes
)
*/

键盘

说明:parse_url($str, PHP_URL_QUERY)从该 url 中提取查询字符串,然后parse_str($query, $arr)解析它,用=>对填充$arr变量。keyvalue

于 2013-09-13T19:09:31.980 回答