Simple function to parse command line options.
Input array is command line arguments and function returns associative array of command line options.
function parseOptions($array) { //parse command line options into associative //array so that each option that starts with //'-' is name and the next item is array of values // $len=sizeof($array); $currentName=""; $options=array(); for ($i = 1; $i < $len; $i++) { $name=$array[$i]; if(strpos($name,"-")===0) { //is option $name=str_replace("-","",$name); $currentName=$name; if($options[$currentName]==NULL) { $options[$currentName]=array(); } } else { $values=$options[$currentName]; array_push($values,$name); $options[$currentName]=$values; } } return $options; }
|