Hey, say I have a url just being passed through my php is there any easy way to get some GET variables that are being passed through it? It's not the actual url of the page or anything.
嘿,说我有一个网址只是通过我的PHP传递是否有任何简单的方法来获得一些通过它传递的GET变量?这不是页面的实际网址或任何内容。
like a just have a string containing
就像一个只有一个字符串包含
http://www.somesite.com/index.php?url=var&file_id=var&test=var
Whats the best way to get the values for those variables?
什么是获取这些变量值的最佳方法?
5 个解决方案
#1
39
parse_str(parse_url($url, PHP_URL_QUERY), $array)
, see the manpage for parse_str for more info.
parse_str(parse_url($ url,PHP_URL_QUERY),$ array),有关详细信息,请参阅parse_str的联机帮助页。
#2
16
$href = 'http://www.somesite.com/index.php?url=var&file_id=var&test=var';
$url = parse_url($href);
print_r($url);
/* Array
(
[scheme] => http
[host] => www.somesite.com
[path] => /index.php
[query] => url=var&file_id=var&test=var
) */
$query = array();
parse_str($url['query'], $query);
print_r($query);
/* Array
(
[url] => var
[file_id] => var
[test] => var
) */
#3
4
It's actually a lot easier than writing any custom functions.
它实际上比编写任何自定义函数容易得多。
$queryStr = $_SERVER['QUERY_STRING'];
$ queryStr = $ _SERVER ['QUERY_STRING'];
#4
0
I'd use something like:
我会使用类似的东西:
preg_match_all('/(\?|&)([^=]+=[^&]*)/', $string , $matches);
then
print_r($matches[2]);
/*
Array
(
[0] => url=var
[1] => file_id=var
[2] => test=var
)
*/
Hope it works 4 u.
希望它有效4你。
#5
-1
A quick google for "PHP GET" gives this page from w3schools:
一个快速的谷歌“PHP GET”从w3schools给这个页面:
#1
39
parse_str(parse_url($url, PHP_URL_QUERY), $array)
, see the manpage for parse_str for more info.
parse_str(parse_url($ url,PHP_URL_QUERY),$ array),有关详细信息,请参阅parse_str的联机帮助页。
#2
16
$href = 'http://www.somesite.com/index.php?url=var&file_id=var&test=var';
$url = parse_url($href);
print_r($url);
/* Array
(
[scheme] => http
[host] => www.somesite.com
[path] => /index.php
[query] => url=var&file_id=var&test=var
) */
$query = array();
parse_str($url['query'], $query);
print_r($query);
/* Array
(
[url] => var
[file_id] => var
[test] => var
) */
#3
4
It's actually a lot easier than writing any custom functions.
它实际上比编写任何自定义函数容易得多。
$queryStr = $_SERVER['QUERY_STRING'];
$ queryStr = $ _SERVER ['QUERY_STRING'];
#4
0
I'd use something like:
我会使用类似的东西:
preg_match_all('/(\?|&)([^=]+=[^&]*)/', $string , $matches);
then
print_r($matches[2]);
/*
Array
(
[0] => url=var
[1] => file_id=var
[2] => test=var
)
*/
Hope it works 4 u.
希望它有效4你。
#5
-1
A quick google for "PHP GET" gives this page from w3schools:
一个快速的谷歌“PHP GET”从w3schools给这个页面: