The following small series for everyone to bring a PHP get '/' parameter value simple method. Small series feel very good, now share to everyone, also for everyone to make a reference. Let's take a look at it with a little knitting.
Through the output $globals can see the "/" parameters are present in $_server[' Path_info '];
Declare an array to get the arguments we passed after '/'
$arr = explode ('/', $_server[' path_info ');//print_r ($arr) View details
PHP is usually made HTTP request, you can use Get or post method to receive parameters, and sometimes need to be executed under the shell command PHP as a script, such as scheduled tasks. This involves the question of how to send a reference to PHP under a shell command, usually in three ways.
One, using $ARGV or $ARGC parameter receive
<?php/** * Use $ARGC $argv accept parameter */echo "received {$ARGC} parameters";p Rint_r ($ARGV);
Perform
[root@dell113 lee]#/usr/local/php/bin/php test.php
1 Parameters received
Array ( [0] = test.php) [root@dell113 lee]#/usr/local/php/bin/php test.php a b C D received 5 parameters array ( [0] + = Test . PHP [1] = a [2] = b [3] = = C [4] + D) [root@dell113 lee]#
Second, using the Getopt function
<?php/** * Use the getopt function */$param _arr = getopt (' a:b: ');p Rint_r ($param _arr);
Perform
[root@dell113 lee]#/usr/local/php/bin/php test.php-a 345Array ( [A] = 345) [root@dell113 lee]#/usr/local/php/ bin/php test.php-a 345-b 12q3array ( [A] = 345 [b] = 12q3) [root@dell113 lee]#/usr/local/php/bin/php Test . php-a 345-b 12q3-e 3322ffArray ( [A] = 345 [b] = 12q3)