1

I'm was wondering if anyone knows of a native function to parse command line options in PHP via the cli that allows repeating options? getopt doesn't like something like: program.php -w "WARNING1" -w "WARNING2"

I would make use of the pipe symbol and get the user to pass me WARNING1|WARNING2 however because each option is a regex they may use this already, and I've seen perl working this way.

So any ideas?

Thanks in advance.

1
  • You could certainly do this by manually reading and parsing the values out of the global $argv variable. That will contain all command line values: php.net/manual/en/reserved.variables.argv.php Commented Dec 18, 2015 at 16:11

1 Answer 1

1

You can retrieve multiple command line options by

  • Using some separator character and options variable with getopt
  • Use regular getopt without -w flag

    php script_name.php Jarrod "cake, tea and ice cream"

will give you, jarrod and cake,tea and ice cream as arguments

Also take a look here : http://php.net/manual/en/function.getopt.php and read more about options and long options.

Sign up to request clarification or add additional context in comments.

1 Comment

Many thanks, it's not quite what I wanted, but the reply is much appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.