Created
April 18, 2015 16:22
-
-
Save j3j5/5c769a5822e1672f2cbe to your computer and use it in GitHub Desktop.
PHP snippet to prompt for an answer on the CLI.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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