php获取url里指定位置的参数
程序员文章站
2022-06-06 12:03:34
...
php获取url里指定位置的参数,因为url后的参数是变动的。怎样获取呢?如www.xxx.com?act=game&st=play&b1=1&round=1,有时候这个url会输出成www.xxx.com?act=game&st=play&b2=2&round=1,其中的b1、b2、b3.。。。一直到b15.怎样获取这个url输出的b1还是b2还是其他及他的值呢
(
[act] => game
[st] => play
[b1] => 1
[round] => 1
)
Array
(
[act] => game
[st] => play
[b2] => 2
[round] => 1
)
回复讨论(解决方案)
把查询字符串输出成一个数组不就行了
用名字访问
$s = 'www.xxx.com?act=game&st=play&b1=1&round=1';parse_str(@array_pop(explode('?', $s)), $a);print_r($a);$s = 'www.xxx.com?act=game&st=play&b2=2&round=1';parse_str(@array_pop(explode('?', $s)), $a);print_r($a);Array
(
[act] => game
[st] => play
[b1] => 1
[round] => 1
)
Array
(
[act] => game
[st] => play
[b2] => 2
[round] => 1
)
parse_str
http://www.w3school.com.cn/php/func_string_parse_str.asp
下一篇: 专栏:数据库那些事儿