Heim > Backend-Entwicklung > PHP-Tutorial > php 简单的路由解析 可以随意设置后缀(html,do,shtml,aspx等等)_PHP教程

php 简单的路由解析 可以随意设置后缀(html,do,shtml,aspx等等)_PHP教程

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Freigeben: 2016-07-13 17:54:31
Original
1783 Leute haben es durchsucht

[php]
if(isset($_SERVER['PATH_INFO'])){ 
      $str=substr($_SERVER['PATH_INFO'],0,strpos($_SERVER['PATH_INFO'],'.')); 
      //获取路径信息(pathinfo)  
      $pathinfo=explode('/',trim($str,'/')); 
      //获取$_GET['m']  
      $_GET['m']=(!emptyempty($pathinfo[0])?$pathinfo[0]:'index'); 
      //将数组单元的开头移除  
      array_shift($pathinfo); 
      //获取$_GET['a]  
      $_GET['a']=(!emptyempty($pathinfo[0])?$pathinfo[0]:'index'); 
       //将数组单元的开头移除  
      array_shift($pathinfo); 
      $num=count($pathinfo); 
      for ($i=0;$i         $_GET[$pathinfo[$i]]=$pathinfo[$i+1]; 
      } 
}else{ 
      $_GET['m']=(!emptyempty($_GET['m'])?$_GET['m']:'index'); 
      $_GET['a']=(!emptyempty($_GET['a'])?$_GET['a']:'index'); 
     if($_SERVER["QUERY_STRING"]){ 
        $m=$_GET['m']; 
        unset($_GET['m']);   //去除数组的m  
        $a=$_GET['a']; 
        unset($_GET['a']);   //去除数组的a  
         
        $query=http_build_query($_GET);  //组成新的URL参数  
        //组合新的URL  
        $url=$_SERVER['SCRIPT_NAME']."/{$m}/{$a}/".str_replace(array("&","="),"/",$query).".html";   //重点在这  
        header("Location:".$url); 
     }   

if(isset($_SERVER['PATH_INFO'])){
   $str=substr($_SERVER['PATH_INFO'],0,strpos($_SERVER['PATH_INFO'],'.'));
   //获取路径信息(pathinfo)
   $pathinfo=explode('/',trim($str,'/'));
   //获取$_GET['m']
   $_GET['m']=(!empty($pathinfo[0])?$pathinfo[0]:'index');
   //将数组单元的开头移除
   array_shift($pathinfo);
   //获取$_GET['a]
   $_GET['a']=(!empty($pathinfo[0])?$pathinfo[0]:'index');
    //将数组单元的开头移除
   array_shift($pathinfo);
   $num=count($pathinfo);
   for ($i=0;$i     $_GET[$pathinfo[$i]]=$pathinfo[$i+1];
   }
}else{
   $_GET['m']=(!empty($_GET['m'])?$_GET['m']:'index');
   $_GET['a']=(!empty($_GET['a'])?$_GET['a']:'index');
  if($_SERVER["QUERY_STRING"]){
   $m=$_GET['m'];
   unset($_GET['m']);   //去除数组的m
   $a=$_GET['a'];
   unset($_GET['a']);   //去除数组的a
   
   $query=http_build_query($_GET);  //组成新的URL参数
   //组合新的URL
   $url=$_SERVER['SCRIPT_NAME']."/{$m}/{$a}/".str_replace(array("&","="),"/",$query).".html";   //重点在这
   header("Location:".$url);
  } 
}

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/477962.htmlTechArticle[php] if(isset($_SERVER[PATH_INFO])){ $str=substr($_SERVER[PATH_INFO],0,strpos($_SERVER[PATH_INFO],.)); //获取路径信息(pathinfo) $pathinfo=explode(/,trim($str,/)); //获取$_...
Verwandte Etiketten:
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Aktuelle Ausgaben
PHP-Datenerfassung?
Aus 1970-01-01 08:00:00
0
0
0
PHP-Erweiterung intl
Aus 1970-01-01 08:00:00
0
0
0
Wie man PHP gut lernt
Aus 1970-01-01 08:00:00
0
0
0
Mehrere PHP-Versionen
Aus 1970-01-01 08:00:00
0
0
0
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage