魏长东

weichangdong

东邪

http_build_query的相对函数

大家都知道php的http_build_query函数能把一个数组,变成一个url字符串,但是要想把一个url字符串变成一个数组呢?

比如需要吧这个字符串给变成key对应value的形式。

$get='act=ad.jump&androidid=a433bf43c56fbbe5&devid=7796bfce-639c-3664-8044-
da5fafd20d3c&version=1.8&klsso=qS4QHBw2zcaRVLH-5kOVBQ-qw8KYxsYU1ZoAYviEM0&k
lperson=n4e4Egh33WgqsHqKRJEsn.tq694_id4v3sqf_Akt3tDT_vdN11sfkyJfxSZLdSZ44Sf6h9
V2sQT9pgQ&userid=1256513&adid=1091&src=http://track.12trackway.com/aff_c?offer
_id=14952&aff_id=1873&aff_sub={clickid}&clickid=1091_7796bfce-639c-3664-8044-
da5fafd20d3c&ts=1425376774&sign=2f8cd4aa2956';
$new = explode('&',$get);
//print_R($new);
foreach ($new as $v) {
    $tmp = explode('=',$v);
    $$tmp[0] = $tmp[1];
    $ok[$tmp[0]] = $tmp[1];
}
print_r($ok);
extract($ok);
//echo $act;
//还原回去
//echo http_build_query($ok);

输出结果

Array (
[act] => ad.jump
[androidid] => a433bf43c56fbbe5 
[devid] => 7796bfce-639c-3664-8044-da5fafd20d3c
[version] => 1.8 
[klsso] => qS4QHBw2zcaRVLH-5kOVBQ-qw8KYxsYU1ZoAYviEM0 
[klperson] => n4e4Egh33WgqsHqKRJEsn.tq694_id4v3sqf_Akt3tDT_vdN11sfkyJfxSZLdSZ44Sf6h9V2sQT9pgQ
[userid] => 1256513
[adid] => 1091 
[src] => http://track.12trackway.com/aff_c?offer_id 
[aff_id] => 1873
[aff_sub] => {clickid}
[clickid] => 1091_7796bfce-639c-3664-8044-da5fafd20d3c 
[ts] => 1425376774
[sign] => 2f8cd4aa2956
)