i recently entered the fascinating world of PHP CLI.
I run then the script on an ubuntu terminal and when i pressed the arrows keys, instead of moving the cursor, it printed the escape codes ^[[A^[[B^[[C^[[D.
If i use the normal terminal the problem doesn't appear. So i guess that into my script something prevents the normal behaviour.
Does someone have any solution?
Thanks for the help!
EDIT:
Looks like it's STDIN, which I use to catch the inputs, the problem! When waiting for STDIN inputs, the terminal shows the wrong characters!! How can I solve this?
I suggest replacing the fgets(STDIN) call with the readline() function, which is available at least in Linux environments. Note that the readline library is not shipped in OS X, although it can be installed separately.
// $input = fgets(STDIN);
$input = readline('Input: ');
If the only reason you need line editing is removing the surplus ´-characters from a drag and dropped file path, you can always trim any extra characters from the string in your script.
$input = readline('Input: ');
$input = trim($input, '´');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With