note 78804 added to features.commandline

From: Date: Sun, 28 Oct 2007 23:51:45 +0000
Subject: note 78804 added to features.commandline
Groups: php.notes 
Request: Send a blank email to php-notes+get-131798@lists.php.net to get a copy of this message
Here's <losbrutos at free dot fr> function modified to support unix like param syntax like <B Crawford> mentions: <?php function arguments($argv) { $_ARG = array(); foreach ($argv as $arg) { if (preg_match('#^-{1,2}([a-zA-Z0-9]*)=?(.*)$#', $arg, $matches)) { $key = $matches[1]; switch ($matches[2]) { case '': case 'true': $arg = true; break; case 'false': $arg = false; break; default: $arg = $matches[2]; } /* make unix like -afd == -a -f -d */ if(preg_match("/^-([a-zA-Z0-9]+)/", $matches[0], $match)) { $string = $match[1]; for($i=0; strlen($string) > $i; $i++) { $_ARG[$string[$i]] = true; } } else { $_ARG[$key] = $arg; } } else { $_ARG['input'][] = $arg; } } return $_ARG; } ?> Sample: eromero@ditto ~/workspace/snipplets $ foxogg2mp3.php asdf asdf --help --dest=/var/ -asd -h Array ( [input] => Array ( [0] => /usr/local/bin/foxogg2mp3.php [1] => asdf [2] => asdf ) [help] => 1 [dest] => /var/ [a] => 1 [s] => 1 [d] => 1 [h] => 1 ) ---- Server IP: 209.41.74.194 Probable Submitter: 189.164.117.190 ---- Manual Page -- http://www.php.net/manual/en/features.commandline.php Edit -- https://master.php.net/note/edit/78804 Del: integrated -- https://master.php.net/note/delete/78804/integrated Del: useless -- https://master.php.net/note/delete/78804/useless Del: bad code -- https://master.php.net/note/delete/78804/bad+code Del: spam -- https://master.php.net/note/delete/78804/spam Del: non-english -- https://master.php.net/note/delete/78804/non-english Del: in docs -- https://master.php.net/note/delete/78804/in+docs Del: other reasons-- https://master.php.net/note/delete/78804 Reject -- https://master.php.net/note/reject/78804 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#131798) next »