1. Go to this page and download the library: Download martijnvdb/php-cli 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/ */
martijnvdb / php-cli example snippets
composer
use Martijnvdb\PhpCli\Cli;
$cli = (new Cli('First CLI App', '0.1.0'))->run();
$cli = new Cli('First CLI App', '0.1.0');
$cli->add('helloworld', function ($input, $output) {
// ...
})
->run();
$cli->add('helloworld', function ($options, $output) {
// This will return all options
$options = $options->all();
// This will return the value of the '--message' option
$message = $options->get('--message');
// Will return the value of the '--message' or '-m' option
$message = $options->get('--message', '-m');
// $options = ["--message" => "Hello, World!"];
// $message = "Hello, World!";
})
$output->line('[bold]Bold Text[/bold]');
$output->line('[red]Red Text[/red]');
$output->line('[bg:green]Green Background[/bg:green]');
$output->line('[bg:white][magenta][italic]Italic magenta text on a white background[/italic][/magenta][/bg:white]');