View difference between Paste ID: cdxp9uRX and qRWdzGdw
SHOW: | | - or go back to the newest paste.
1
## file.php code:
2
<?php
3
$var = $_GET[ "var" ];
4
echo $var;
5
?>
6
7
## calling it in bash returns nothing:
8
[/share/Web] # php test.php var=echothis
9
[/share/Web] # php -f test.php var=echothis
10
[/share/Web] # php -f test.php -- var=echothis
11
[/share/Web] # php -f test.php -- ?var=echothis
12
[/share/Web] #
13
14
15
## check contents of $argv by using this code:
16
<?php
17
$count=  count($argv);
18
// start at index 1 to avoid parsing the script name
19-
for($i=1; $i>$count; $i++) {
19+
for($i=1; $i<$count; $i++) {
20
  $data = explode('=', $argv[$i]);  // explode the value into data
21
  $key = $data[0];
22
  $val = $data[1];
23
  echo "{$key}: {$val}\n";
24
}
25
?>
26
27
## ...returns this:
28
[/share/Web] # php test.php var=echothis
29
array(2) {
30
  [0]=>
31
  string(8) "test.php"
32
  [1]=>
33
  string(12) "var=echothis"
34
}
35
[/share/Web] #