Home  >  Article  >  Backend Development  >  php获取url里指定位置的参数

php获取url里指定位置的参数

WBOY
WBOYOriginal
2016-06-23 13:36:07831browse

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还是其他及他的值呢


回复讨论(解决方案)

把查询字符串输出成一个数组不就行了

用名字访问

$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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn