PHP code example of yeriomin / getopt

1. Go to this page and download the library: Download yeriomin/getopt 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/ */

    

yeriomin / getopt example snippets



pt = new \Yeriomin\Getopt\Getopt();
$arguments = $getopt->getArguments();

echo $getopt->option1; // "value1"
echo $getopt->optionWhichIsNotProvided; // null

$optionDefinition = new \Yeriomin\Getopt\OptionDefinition(
    'c',
    'config',
    'Path to a configuration file'
);
$getopt->addOptionDefinition($optionDefinition);

$optionDefinition = new \Yeriomin\Getopt\OptionDefinition(
    'c',
    'config',
    'Path to a configuration file',
    true
);
$getopt->addOptionDefinition($optionDefinition);


pt = new \Yeriomin\Getopt\Getopt();
$optionConfig = new \Yeriomin\Getopt\OptionDefinition(
    'c',
    'config',
    'Path to a configuration file',
    true
);
$getopt->addOptionDefinition($optionConfig);
$optionHelp = new \Yeriomin\Getopt\OptionDefinition(
    'h',
    'help',
    'Show script help message',
);
$getopt->addOptionDefinition($optionHelp);
try {
    $configPath = $getopt->c;
} catch (\Yeriomin\Getopt\GetoptException $e) {
    echo $e->getMessage() . "\n";
    echo $getopt->getUsageMessage();
    exit(1);
}

array(1) {
  'option1' =>
  string(6) "value1"
}