The incoming URL is parsed to obtain the command array.
$_SERVER["REQUEST_URI"] contains '/urlrouter/part_1/commandOne'
Which when exploded creates the following array:
Array
(
[0] =>
[1] => urlrouter
[2] => part_1
[3] => commandOne
)
$_SERVER["SCRIPT_NAME"] contains '/urlrouter/part_1/index.php'
Which when exploded creates the following array:
Array
(
[0] =>
[1] => urlrouter
[2] => part_1
[3] => index.php
)
After removing each position in $_SERVER["REQUEST_URI"] that matches the same position in $_SERVER["SCRIPT_NAME"]
the following command array is obtained.
Array
(
[0] => commandOne
)
The command array is then used in a switch statement to select the code to exectute based on the contents of first position of the command array.
Click on the following links to see the results of various commands or type some into the address bar after '.../part_1/'.
Root
Command One
Command Two
Command Two with parameters
Command Results:
Command:
commandOne