Home > Backend Development > PHP Tutorial > PHP simple route analysis, you can set the suffix at will (html, do, shtml, aspx, etc.)_PHP tutorial

PHP simple route analysis, you can set the suffix at will (html, do, shtml, aspx, etc.)_PHP tutorial

WBOY
Release: 2016-07-13 17:54:31
Original
1754 people have browsed it

[php]
if(isset($_SERVER['PATH_INFO'])){
$str=substr($_SERVER['PATH_INFO'],0,strpos($_SERVER['PATH_INFO'],'.'));
//Get path information (pathinfo)
$pathinfo=explode('/',trim($str,'/'));
//Get $_GET['m']
$_GET['m']=(!emptyempty($pathinfo[0])?$pathinfo[0]:'index');
//Remove the beginning of the array unit
​​ array_shift($pathinfo);
//Get $_GET['a]
$_GET['a']=(!emptyempty($pathinfo[0])?$pathinfo[0]:'index');
//Remove the beginning of the array unit
​​ array_shift($pathinfo);
       $num=count($pathinfo);
for ($i=0;$i<$num;$i+=2){
          $_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']); //Remove m from the array
          $a=$_GET['a'];
         unset($_GET['a']); //Remove a from the array
                                                                  $query=http_build_query($_GET); // Form new URL parameters
//Combine a new URL
$url=$_SERVER['SCRIPT_NAME']."/{$m}/{$a}/".str_replace(array("&","="),"/",$query).".html" ; //The point is here
header("Location:".$url);
}  
}

if(isset($_SERVER['PATH_INFO'])){

$str=substr($_SERVER['PATH_INFO'],0,strpos($_SERVER['PATH_INFO'],'.'));
//Get path information (pathinfo)
$pathinfo=explode('/',trim($str,'/'));
//Get $_GET['m']
$_GET['m']=(!empty($pathinfo[0])?$pathinfo[0]:'index');
//Remove the beginning of the array unit
Array_shift($pathinfo);
//Get $_GET['a]
$_GET['a']=(!empty($pathinfo[0])?$pathinfo[0]:'index');
//Remove the beginning of the array unit
Array_shift($pathinfo);
$num=count($pathinfo);
for ($i=0;$i<$num;$i+=2){
$_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']); //Remove m
from the array $a=$_GET['a'];
Unset($_GET['a']); //Remove a
from the array
$query=http_build_query($_GET); //Create new URL parameters
//Combine new URL
$url=$_SERVER['SCRIPT_NAME']."/{$m}/{$a}/".str_replace(array("&","="),"/",$query).".html" ; //The point is here
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],.)); //Get path information (pathinfo) $pathinfo=explode(/,trim($str,/)); //Get $_...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template