-
-
Save bricejulia/41aa1a562bd93e2d807f7219b2c6e844 to your computer and use it in GitHub Desktop.
PHP snippet to prompt for an answer on the CLI.
This file contains hidden or 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