Tobiasz Cudnik

PHP in CLI using $argv

In Snippets on 05.10.2008 at 3:05

Just an example showing how easy it is to implement CLI in PHP scripts. Sandbox.php file:

#!/usr/bin/php
<?php
var_dump($argv);
?>

./sandbox.php param1 –param2 param3 param4 –param5 -p 6 -fbi

array(9) {
[0]=>
string(13) "./sandbox.php"
[1]=>
string(6) "param1"
[2]=>
string(8) "--param2"
[3]=>
string(6) "param3"
[4]=>
string(6) "param4"
[5]=>
string(8) "--param5"
[6]=>
string(2) "-p"
[7]=>
string(1) "6"
[8]=>
string(4) "-fbi"
}

All comments are screened for appropriateness. Commenting is a privilege, not a right. Good comments will be cherished, bad comments will be deleted.