PHP pseudo-static use is mainly to hide the passed parameter name. Today we introduce to you a total of four pseudo-static PHP method, I hope we can further deepen the understanding of PHP pseudo-static through these four methods. Here's the full method code: [pre]
<? php // pseudo-static method two // localhost / php100 / test.php / 1/2 $ filename = basename ($ _ SERVER ['SCRIPT_NAME']); echo $ _SERVER ['SCRIPT_NAME']. "<br>"; // /php100/test.php echo $ filename. "<br>"; // test.php if (strtolower ($ filename) == 'test.php') { if (! empty ($ _ GET [id])) {$ id = intval ($ _ GET [id]); echo $ id. "<br>"; $ action = intval ($ _ GET [action]); echo $ action. "<br>";} else { $ nav = $ _ SERVER ['REQUEST_URI']; echo "1:". $ nav. "<br>"; // /php100/test.php/1/2 $ script = $ _ SERVER ['SCRIPT_NAME']; echo "2:". $ script. "<br>"; // /php100/test.php $ nav = ereg_replace ("^ $ script", "", urldecode ($ nav)); echo $ nav. "<br>"; // / 1/2 $ vars = explode ("/", $ nav); print_r ($ vars); // Array ([0] => [1] => 1 [2] => 2) echo "<br>"; $ id = intval ($ vars [1]); $ action = intval ($ vars [2]);} echo $ id. '&'. $ action;} ?> [/ pre]
[pre]
<? php // pseudo-static method three function mod_rewrite () { global $ _GET; $ nav = $ _ SERVER ["REQUEST_URI"]; echo $ nav. "<br>"; $ script_name = $ _ SERVER ["SCRIPT_NAME"]; echo $ script_name. ""; $ nav = substr (ereg_replace ("^ $ script_name", "", urldecode ($ nav)), 1); $ nav = preg_replace ("/ ^. ht (m) {1} (l) {0,1} $ /", "", $ nav); // The phrase is Remove the tail of .html or .htm echo $ nav. ";"; $ vars = explode ("/", $ nav); print_r ($ vars); echo "<br>"; for $ i = 0; $ i <Count ($ vars); $ i + = 2) {$ _GET ["$ vars [$ i]"] = $ vars [$ i + 1]; } return $ _GET; } mod_rewrite (); $ year = $ _ GET ["year"]; // the result is '2006' echo $ year. "<br>"; $ action = $ _ GET ["action"]; // result is '_add' echo $ action; ?> [/ pre]
[pre]
<? php // pseudo-static method four // Use the server variable to get the PATH_INFO information In this example, /1,100,8630.html is the portion of the script that executes if (@ $ path_info = $ _ SERVER ["PATH_INFO"]) { // Regularly match the 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!'); ?> [/ pre]
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.