PHPBuilder - Replacing Perl Scripts with PHP Scripts Page 4



RSS Twitter
Articles Tricks And Hacks

Replacing Perl Scripts with PHP Scripts - Page 4

by: Jayesh Jain
|
November 11, 2002

Using Arguments in Scripts

As you all know we can use arguments with PHP (remember world.php was an argument to the PHP interpreter), similarly we can use arguments in our scripts. Wondering how? Lets look at it.
All the arguments passed to your script are stored in a zero based global array variable $argv, also there is one more global variable $argc which holds number of arguments passed to the script (hey all you people coming from C/C++ background this should be familiar to you). Please note: $argc will always be one or more than one as the script name is always the first argument. Here is the code which shall display the total number of argument passed and also will display the arguments

<?
   
echo "Total argument passed are : $argc \n";
   for( 
$i $i <= $argc -;$i++)
   {
     echo 
"Argument $i : $argv[$i] \n";
   }
?>
Assuming this is stored in a file argument.php you could test this script by running something like this
php argument.php arg1 arg2
php argument example

« Previous Page
1
|
2
|
3
|
4
|
5
|
6
Next Page »

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Jayesh Jain

Comment:



Comment:

(Maximum characters: 1200). You have characters left.