Parsing command arguments in PHP

后端 未结 11 757
萌比男神i
萌比男神i 2020-12-11 01:19

Is there a native \"PHP way\" to parse command arguments from a string? For example, given the following string:

foo \"bar \\\"baz         


        
11条回答
  •  我在风中等你
    2020-12-11 01:39

    I would recommend going another way. There is already a "standard" way of doing command line arguments. it's called get_opts:

    http://php.net/manual/en/function.getopt.php

    I would suggest that you change your script to use get_opts, then anyone using your script will be passing parameters in a way that is familiar to them and kind of "industry standard" instead of having to learn your way of doing things.

提交回复
热议问题