/* * 函數說明:獲取URL某個參數的值 * * @access public * @param $url 路徑 * @param $key 要獲取的參數 * @return string 返回參數值 */ 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; }
使用方式:
例如:
url:/intro.php?cid=9&NavID=3
獲取cid
直接調用函數:
getQuerystr(‘/intro.php?cid=9&NavID=3’, 'cid'))