PHP code example of dxw / optionparser

1. Go to this page and download the library: Download dxw/optionparser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dxw / optionparser example snippets


$parser = new OptionParser;
// add a rule that looks for the short "a" flag
$parser->addRule('a');
// add a rule that looks for the long "long-option" flag
$parser->addRule('long-option');
// add a rule that looks for the short "b" flag or long "big" flag
$parser->addRule('b|big');
// to indicate an optional parameter, use a colon after the flag name
$parser->addRule('c:');
// likewise, to indicate a reporting', 'set_error_reporting');

try {
    $parser->parse();
} catch (Exception $e) {
    die("Error parsing arguments: " . $e->getMessage());
}

$parser->addHead("Usage: myprog [ options ]\n");

try {
    $parser->parse();
} catch (Exception $e) {
    die($parser->getUsage());
}