命令行PHP:混合fread(STDIN,...)和fgets(STDIN)的问题

I am working on a command-line-script witch uses fread (for yes/no,...) and fgets (for manually validating values,...).

The problem is if I enter more than ... chars ( is a char, too), this chars are already inputed in the next fgets/fread-function.

I tried fflush(STDIN), but it didn't work. I also tried stream_get_line(STDIN,1024); which was recommended by someone in a simmelar question, but then I have to input nearly unendless much chars until the programm continues (I quit).

How to get PHP to delete keyboard-buffer before using fgets/fread?

If your PHP is compiled with the Readline module (it's quite common) you may just use readline()

http://php.net/manual/en/function.readline.php

$input = readline( 'Prompt: ' );

readline() simplifies the process of reading input from the terminal.