$url = "http://shopnc.localhost/shop/index.php?act=goods&op=index&goods_id=25220"; $s = parse_url($url); var_dump($s); $t = parse_str($s[‘query‘],$arr); var_dump($arr);
array ‘scheme‘ => string ‘http‘ (length=4) ‘host‘ => string ‘shopnc.localhost‘ (length=16) ‘path‘ => string ‘/shop/index.php‘ (length=15) ‘query‘ => string ‘act=goods&op=index&goods_id=25220‘ (length=33) array ‘act‘ => string ‘goods‘ (length=5) ‘op‘ => string ‘index‘ (length=5) ‘goods_id‘ => string ‘25220‘ (length=5)
这种类型解析的很好,但是下面情况就不行了
$url ="http://ci.localhost/index.php/home/adminlogin"; //$url = "http://shopnc.localhost/shop/index.php?act=goods&op=index&goods_id=25220"; $s = parse_url($url); var_dump($s); $t = parse_str($s[‘query‘],$arr); var_dump($arr);
$url ="http://ci.localhost/index.php/home/adminlogin"; //$url = "http://shopnc.localhost/shop/index.php?act=goods&op=index&goods_id=25220"; $s = parse_url($url); var_dump($s); $t = parse_str($s[‘query‘],$arr); var_dump($arr); var_dump(pathinfo($url)); //不行 var_dump(basename($url)); var_dump(dirname($url)); //这种模式类型都不行,所以换个思路 $mm = $s[‘path‘]; $g = explode("/",$mm); var_dump($g); //unset($g[‘0‘]); //var_dump($g); list($b,$n,$acttion,$function) = $g; echo ‘<br>‘; echo $n; echo ‘<br>‘; echo $acttion; echo ‘<br>‘; echo $function;
结果:
时间: 2024-10-08 02:18:52