1. Go to this page and download the library: Download jdwx/args 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/ */
jdwx / args example snippets
declare( strict_types = 1 );
the script name from the arguments for our example.
$argv = array_slice( $argv, 1 );
$args = new Arguments( $argv );
echo $args->shiftString(), "\n"; # Echoes "Hello," in the given example.
# If the next argument is "prefix_example," $st will be set to "example."
# In this example, the i_bConsume flag is not set, so the argument will not
# be consumed.
$args = new JDWX\Args\Arguments( [ 'prefix_example' ] );
if ( $st = $args->peekString( 'prefix_' ) ) {
echo "Got: {$st}\n";
$st2 = $args->shiftString();
echo "Shifted: {$st2}\n"; # Argument was not consumed.
} else {
echo "Nope!\n";
}
$rKeywords = [ 'example', 'demo', 'test' ];
# If the next argument is "example," $st will be set to "example." In this example,
# the consume flag is set so the argument is consumed if (and only if) it matches.
# The default is kept as false for consistency with peekString(), but usually
# you do want to consume keyword-matching arguments.
if ( $st = $args->peekKeywords( $rKeywords, i_bConsume: true ) ) {
echo "Keyword: {$st}\n";
} else {
echo "Nope!\n";
}