Skip to content

Instantly share code, notes, and snippets.

@j3j5
Created April 18, 2015 16:22
Show Gist options
  • Save j3j5/5c769a5822e1672f2cbe to your computer and use it in GitHub Desktop.
Save j3j5/5c769a5822e1672f2cbe to your computer and use it in GitHub Desktop.
PHP snippet to prompt for an answer on the CLI.
function prompt_answer($exit = TRUE) {
$handle = fopen ("php://stdin","r");
$line = fgets($handle);
if(trim($line) !== 'y' && !empty(trim($line))) {
fclose($handle);
if($exit) {
echo "ABORTING!" . PHP_EOL;
exit;
} else {
return FALSE;
}
}
if(!$exit) {
return TRUE;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment