In PHP, I can read data from the command line with the following code
$stream = STDIN; $test = fgets($stream); echo $test;
This works well for easy typing. However, if I try to use something like a back arrow, my shell looks like this
This is a test^[[D^[[D^[[D
i, then the escape sequence of the key sequence ^[[D PHP itself interprets the arrow keys, i.e. by entering this
This is a test^[[D^[[D^[[D^[[Dsecond test
will output this
This is a second test
However, I would like the shell to “correctly” (that is, do what I think they should do, and not literally what I sent) interpret the arrow keys so that the entry point moves during input.
Is this possible in PHP? With the extension? No extension? I tried the fgets($stream, 1) options, but it seems that PHP just hangs until the user enters an input key.
source share