Created
April 10, 2011 06:51
-
-
Save hakre/912112 to your computer and use it in GitHub Desktop.
Just for fun, here is a compacted version:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function parseArgs($argv){ | |
array_shift($argv); $o = array(); | |
foreach ($argv as $a){ | |
if (substr($a,0,2) == '--'){ $eq = strpos($a,'='); | |
if ($eq !== false){ $o[substr($a,2,$eq-2)] = substr($a,$eq+1); } | |
else { $k = substr($a,2); if (!isset($o[$k])){ $o[$k] = true; } } } | |
else if (substr($a,0,1) == '-'){ | |
if (substr($a,2,1) == '='){ $o[substr($a,1,1)] = substr($a,3); } | |
else { foreach (str_split(substr($a,1)) as $k){ if (!isset($o[$k])){ $o[$k] = true; } } } } | |
else { $o[] = $a; } } | |
return $o; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@see https://github.com/pwfisher/CommandLine.php