您好,欢迎访问一九零五行业门户网

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

[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);
  } 
}
http://www.bkjia.com/phpjc/477962.htmlwww.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,/)); //获取$_...
其它类似信息

推荐信息