', $default=false ) { // keep asking until a non-empty response is given do { // display the prompt echo $prompt; // read input and remove CRLF $cmd = chop( fgets( STDIN ) ); } while ( empty( $default ) and empty( $cmd ) ); return $cmd ?: $default; } $question = cli_prompt( 'What is your question? ' ); echo 'Q: ', $question, PHP_EOL; echo 'A: ', $fortunes[ array_rand( $fortunes ) ], PHP_EOL;