PHP code example of yanghuxiao / phpcli

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

    

yanghuxiao / phpcli example snippets


// If you installed via composer, just use this code to requrie autoloader on the top of your projects.
ine option. Returns TRUE if the option exists, but doesn't have a value, and is simply acting as a flag.
PHPCli::getOption('a');

// Enter a number of empty lines
PHPCli::newLine(2);

// Outputs a string to the cli.
PHPCli::write('PHPCli','green','yellow');

// Clears the screen of output
PHPCli::clearScreen();

// Waits a certain number of seconds, optionally showing a wait message and waiting for a key press.
PHPCli::wait(3);

// Outputs an error to the CLI using STDERR instead of STDOUT
PHPCli::error('error.....');

// Asks the user for input.  This can have either 1 or 2 arguments.
PHPCli::prompt();
$color = PHPCli::prompt('What is your favorite color?');
$color = PHPCli::prompt('What is your favourite color?', 'white');
$ready = PHPCli::prompt('Are you ready?', array('y','n'));

// Displays a progress bar on the CLI. You must call it repeatedly to update it. Set $thisStep = false to erase the progress bar.
for ($i=0; $i < 100; $i++) { 
	PHPCli::showProgress($i,100);
	sleep(1);
}