Skip to content

Instantly share code, notes, and snippets.

@vancouverwill
Created April 21, 2017 14:53
Show Gist options
  • Save vancouverwill/7f2245d3f2890786facb6f5b2a5f6497 to your computer and use it in GitHub Desktop.
Save vancouverwill/7f2245d3f2890786facb6f5b2a5f6497 to your computer and use it in GitHub Desktop.
PHP simple commnd line implentation
<?php fwrite(STDOUT, 'Please enter Employee ID'.PHP_EOL);
// Read the input
$employee_id = fgets(STDIN);
fwrite(STDOUT, 'Employee ID : '.$employee_id.PHP_EOL.PHP_EOL);
fwrite(STDOUT, 'Please enter Employee auth V2 hash'.PHP_EOL);
$employee_hash = fgets(STDIN);
fwrite(STDOUT, 'Employee auth V2 hash : '.$employee_hash.PHP_EOL.PHP_EOL);
fwrite(STDOUT, 'Pick some colors (enter the letter and press return)'.PHP_EOL);
// An array of choice to color
$colors = [
'a'=>'Red',
'b'=>'Green',
'c'=>'Blue',
];
fwrite(STDOUT, 'Enter \'q\' to quit'.PHP_EOL);
// Display the choices
foreach ( $colors as $choice => $color ) {
fwrite(STDOUT, $choice.':'. $color.PHP_EOL);
}
// Loop until they enter 'q' for Quit
do {
// A character from STDIN, ignoring whitespace characters
do {
$selection = fgetc(STDIN);
} while ( trim($selection) === '' );
if ( array_key_exists($selection,$colors) ) {
fwrite(STDOUT, 'You picked '.$colors[$selection].PHP_EOL);
}
} while ( $selection !== 'q' );
// Exit correctly
exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment