Pseudo static HTML PHP pseudo-static four ways to pass parameter names

Source: Internet
Author: User
Tags vars
Pseudo static method one:

Copy the Code code as follows:


Pseudo-static method one
Localhost/php100/test.php?id|1@action|2
$PHP 2html_fileurl = $_server["Request_uri"];
echo $Php 2html_fileurl. "
";
/php100/test.php?id|1@action|2
$PHP 2html_urlstring = Str_replace ("?", "" ", Str_replace ("/"," ", STRRCHR (STRRCHR ($Php 2html_fileurl,"/"),"? "));
echo $Php 2html_urlstring. "
";
Id|1@action|2
$PHP 2html_urlquerystrlist = explode ("@", $Php 2html_urlstring);
Print_r ($Php 2html_urlquerystrlist);
Array ([0] = id|1 [1] = action|2) echo "
";
foreach ($Php 2html_urlquerystrlist as $Php 2html_urlquerystr) {
$PHP 2html_tmparray = explode ("|", $Php 2HTML_URLQUERYSTR);
Print_r ($Php 2html_tmparray);
Array ([0] = = id [1] = 1); Array ([0] = = action [1] = 2)
echo "
";
$_get[$Php 2html_tmparray[0]] = $Php 2html_tmparray[1];
}
Echo ' false static: $_get variable
';
Print_r ($_get);
Array ([id|1@action|2] = [id] = 1 [action] + 2) echo "
";
echo "";
Echo $_get[id]. "
";
1 echo $_get[action];
2
?>


Copy the Code code as follows:


Pseudo static method two:
Pseudo-static method two
Localhost/php100/test.php/1/2
$filename = basename ($_server[' script_name ');
echo $_server[' Script_name ']. "
";///php100/test.php
echo $filename. "
";//test.php
if (Strtolower ($filename) = = ' test.php ') {
if (!empty ($_get[id])) {
$id =intval ($_get[id]);
echo $id. "
";
$action =intval ($_get[action]);
echo $action. "
";
}else{
$nav =$_server[' Request_uri '];
echo "1:" $nav. "
";///PHP100/TEST.PHP/1/2
$script =$_server[' Script_name '];
echo "2:" $script. "
";///php100/test.php
$nav =ereg_replace ("^ $script", "", UrlDecode ($nav));
echo $nav. "
"; /1/2
$vars =explode ("/", $nav);
Print_r ($vars);//Array ([0] = [1] = 1 [2] = 2)
echo "
";
$id =intval ($vars [1]);
$action =intval ($vars [2]);
}
echo $id. ' & '. $action;
}
?>


Pseudo static method Three:

Copy the Code code as follows:


Pseudo-static method three
function Mod_rewrite () {
Global $_get;
$nav =$_server["Request_uri"];
echo $nav. "
";
$script _name=$_server["Script_name"];
echo $script _name. "
";
$nav =substr (ereg_replace ("^ $script _name", "", UrlDecode ($nav)), 1);
echo $nav. "
";
$nav =preg_replace ("/^.ht (m) {1} (l) {0,1}$/", "", $nav);//This sentence is removed from the tail. html or. htm
echo $nav. "
";
$vars = Explode ("/", $nav);
Print_r ($vars);
echo "
";
for ($i =0; $i
$_get["$vars [$i]"]= $vars [$i +1];
}
return $_get;
}
Mod_rewrite ();
$year =$_get["Year"];//result for ' 2006 '
echo $year. "
";
$action =$_get["Action"];//result for ' _add '
Echo $action;
?>


Pseudo static method four:

Copy the Code code as follows:


Pseudo-static method four
Use the server variable to get path_info information in this case,/1,100,8630.html is the part that executes the script name.
if (@ $path _info =$_server["Path_info"]) {
Regular match parameters
if (Preg_match ("/\/(\d+), (\d+), (\d+) \.html/si", $path _info, $arr _path)) {
$gid =intval ($arr _path[1]); Get value 1
$sid =intval ($arr _path[2]); Get Value 100
$softid =intval ($arr _path[3]); Get Value 8630
}else die ("path:error!");
Equivalent to soft.php?gid=1&sid=100&softid=8630
}else die (' path:nothing! ');
?>

The above describes the pseudo-static HTML PHP pseudo-static four methods to pass the parameter name, including the pseudo-static HTML content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.