Creating the parser

Creating the parser --  how to create a parser using PHP code or an XML definition file

Console_CommandLine constructor

Console_CommandLine constructor takes an optional array of parameters explained in the table below. Note that if you are using an XML definition file, you can pass these parameters in it (see XML example for details).

表 38-1Available parameters

nametyperequireddescription
namestringno, default to $argv[0] if not giventhe name of your program
descriptionstringno, but recommended for the help messagethe description of your program: this should explain what your program is supposed to do
versionmixed (string or numeric)no, note that if not given, the --version option will not be availablethe program version number
add_help_optionbooleanno, default to TRUEif set to FALSE the parser will not generate automatically the "help" option
add_version_optionbooleanno, default to TRUEif set to FALSE the parser will not generate automatically the "version" option
force_posixbooleanno, default to FALSEif set to TRUE, the parser will force POSIX compliance (please see the gettext manual for more information)

Using PHP code

The examples below demonstrate how to instanciate Console_CommandLine and build a parser using PHP code.

Using an XML definition file

The examples below demonstrate how to instanciate Console_CommandLine and build a parser using an XML definition file, this can be very useful if you have a big program or if you need to reuse your user interface settings for a web frontend for example.

Note: Using and XML string you would have called fromXmlString()() instead of fromXmlFile()() of course.