php正则表达式如何获取url里面的后面id数字

2024-12-28 10:37:19
推荐回答(1个)
回答1:

private function getQuerystr($url,$key){
$res = '';
$a = strpos($url,'?');
if($a!==false){
$str = substr($url,$a+1);
$arr = explode('&',$str);
foreach($arr as $k=>$v){
$tmp = explode('=',$v);
if(!empty($tmp[0]) && !empty($tmp[1])){
$barr[$tmp[0]] = $tmp[1];
}
}
}
if(!empty($barr[$key])){
$res = $barr[$key];
}
return $res;
}

getQuerystr($url,'id');