PHP code example of php-pmd / console

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

    

php-pmd / console example snippets



use PhpPmd\Console;
Console::stdout('Hello, World!');


use PhpPmd\Console;
$db_host = Console::prompt('database host', ['default' => 'localhost']);


use PhpPmd\Console;
$file = Console::prompt('File', [
    's_readable($input)) {
            return true;
        } else {
            $error = 'Path given is not a readable file';
            return false;
        }
    }
]);


use PhpPmd\Console;
$sure = Console::confirm('are you sure?');


use PhpPmd\Console;
$opt = Console::select('apply this patch?',
    ['y' => 'yes', 'n' => 'no', 'a' => 'all']
);


use PhpPmd\Console;
Console::stdout('Working ... ');
Console::work(function($socket) { // $socket is optional, defaults to a spinner
    $n = 100;
    for ($i = 1; $i <= $n; $i++) {
        // do whatever it is you need to do
        socket_write($socket, "[$i/$n]\n");
        sleep(1); // sleep is good for you
    }
});
Console::stdout("%g[DONE]%n\n");


use PhpPmd\Console;
Console::output('this is %rcolored%n and %Bstyled%n');