handy little bit of code I wrote to take arguments from the command line and parse them for use in my apps.
<?php
$i = implode(" ",$argv); $e = explode("-",$i); while (list($index,$value) = each($e)){
$param = rtrim(strrev(stristr(strrev($value),'=')),"=");
$setting = ltrim(stristr($value,'='),"=");
echo "Array index is ".$index." and value is ".$value."\r\n";
echo "Parameter is ".$param." and is set to ".$setting."\r\n\r\n";
}
?>
when run from the CLI this script returns the following.
[root@fedora4 ~]# php a.php -val1=one -val2=two -val3=three
Array index is 0 and value is a.php
Parameter is and is set to
Array index is 1 and value is val1=one
Parameter is val1 and is set to one
Array index is 2 and value is val2=two
Parameter is val2 and is set to two
Array index is 3 and value is val3=three
Parameter is val3 and is set to three
[root@fedora4 ~]#