PHP Get user input without having to press return key

Hi, I am using PHP in CLI mode (command line interface)

I would like to receive the key that the user enters, and immediately send it to the program without having to press the return key (Enter Key) So, for example, I liked typing a letter that the user enters immediately. Therefore, if the user enters "a", he immediately displays "a" on the command line. How should I do it?

 do {  
     $selection = fgetc(STDIN);  
 fwrite(STOUT, "$selection");
 } while ( trim($selection) == '' );  
+3
source share
2 answers

There are several ways to disable input buffering:

http://www.mail-archive.com/ php-general@lists.php.net /msg151195.html seems to work:

exec("stty -icanon min 0 time 0");

: http://bugs.php.net/bug.php?id=34972, stream_set_blocking(STDIN, false);, ,

+2

stdin, ncurses.

+1

All Articles