php如何獲取url某個參數的值。


/*
 * 函數說明:獲取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'))

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM