Skip to content

Instantly share code, notes, and snippets.

@hakre
Created April 10, 2011 06:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hakre/912112 to your computer and use it in GitHub Desktop.
Save hakre/912112 to your computer and use it in GitHub Desktop.
Just for fun, here is a compacted version:
<?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;
}
?>
@pwfisher
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment