>  기사  >  php教程  >  php路由URI

php路由URI

PHP中文网
PHP中文网원래의
2016-05-25 17:11:361595검색

   1. [代码]php路由  

<?
    function seo_uri (){
        $uri_arr = explode("/",trim($_SERVER[&#39;REQUEST_URI&#39;],&#39;/&#39;));
        $web_root_str = strtr(WEB_ROOT,&#39;/&#39;,&#39;\\&#39;);
        $root_path_arr = explode(&#39;\\&#39;,trim($web_root_str,&#39;\\&#39;));
        $root_path_count = count($root_path_arr);
        foreach($uri_arr as $key=>$val){
            if($val==$root_path_arr[$root_path_count-1]){
                $uri_arr_start = $key;
            }
        }
        if($uri_arr_start>=&#39;0&#39;){
            $uri_new = array_slice($uri_arr,$uri_arr_start+1);
        }else{
            $uri_new = $uri_arr;
        }
        $uri[&#39;mod&#39;]=isset($_GET[&#39;mod&#39;])?$_GET[&#39;mod&#39;]:(isset($uri_new[&#39;0&#39;])?(!empty($uri_new[&#39;0&#39;])?$uri_new[&#39;0&#39;]:"index"):"index");
        $uri[&#39;act&#39;]=isset($_GET[&#39;act&#39;])?$_GET[&#39;act&#39;]:(isset($uri_new[&#39;1&#39;])?(!empty($uri_new[&#39;1&#39;])?$uri_new[&#39;1&#39;]:"index"):"index");
        if(count($uri_new)>2){
            $uri[&#39;uri&#39;] = array_slice($uri_new,1);
        }
        return $uri;
    }
?>

                   

                   

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.