Jul 24 2008

PHP command line agrument

Category: PHPBipin Balakrishnan @ 12:31 pm

php.gif

We can pass command line argument to a PHP script as in any other programming language when we run it in the cli mode.For example make script called test.php in your editor.Copy paste content as follows.

<?php
echo $argv[0];
echo $argv[1];
echo $argv[2];
?>

Run the program as follows with command line argument as follows.

bipin@bipin-laptop:~/php$ php  test.php 10 22

Here the command line arguments are 10 and 22.The PHP script will take the argument as an array argv[] with the first element in the array (agrv[0]) as the program name and the arguments passed being held after that.

Tags: , ,

Leave a Reply