PHP function to parse command line options PDF Print E-mail
Thursday, 26 October 2006
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;
}
Last Updated ( Friday, 01 February 2008 )
 
Next >

Newsflash

SCLEC-NXT, Softabar Command Line Email Client v2.0.0, has been released!

More details here.

 

Social Bookmark

Add to: Mr. Wong Add to: Power-Oldie Add to: Linkarena Add to: Digg Add to: Del.icoi.us Add to: Reddit Add to: Jumptags Add to: Upchuckr Add to: Simpy Add to: StumbleUpon Add to: Slashdot Add to: Netscape Add to: Furl Add to: Yahoo Add to: Blogmarks Add to: Diigo Add to: Technorati Add to: Newsvine Add to: Blinkbits Add to: Ma.Gnolia Add to: Smarking Add to: Netvouz Add to: Folkd Add to: Spurl Add to: Google Add to: Blinklist Information
Social Bookmarking
(c) 2005-2008 Softabar. All rights reserved.
Joomla Templates by JoomlaShack Joomla Templates