List Info

Thread: note 78093 added to features.commandline




note 78093 added to features.commandline
user name
2007-09-27 07:54:32
an another "another variant" :

<?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];
      }
      $_ARG[$key] = $arg;
    }
    else
    {
      $_ARG['input'][] = $arg;
    }
  }
  return $_ARG;
}
?>

$php myscript.php arg1 -arg2=val2 --arg3=arg3 -arg4 --arg5
-arg6=false

Array
(
    [input] => Array
        (
            [0] => myscript.php
            [1] => arg1
        )

    [arg2] => val2
    [arg3] => arg3
    [arg4] => true
    [arg5] => true
    [arg5] => false
)
----
Server IP: 217.174.196.197
Probable Submitter: 81.255.192.131
----
Manual Page -- http://www.php.net/manual/en/features.commandline.php
Edit        -- https://master
.php.net/note/edit/78093
Del: integrated  -- h
ttps://master.php.net/note/delete/78093/integrated
Del: useless     -- http
s://master.php.net/note/delete/78093/useless
Del: bad code    -- htt
ps://master.php.net/note/delete/78093/bad+code
Del: spam        -- https:/
/master.php.net/note/delete/78093/spam
Del: non-english -- 
https://master.php.net/note/delete/78093/non-english
Del: in docs     -- http
s://master.php.net/note/delete/78093/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/78093
Reject      -- https://mast
er.php.net/note/reject/78093
Search      -- https://
master.php.net/manage/user-notes.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )