I have a problem receiving multibyte character through PHP CLI. I have a little script that reads from STDIN:
<?php
while(true) {
# also not working, but is similar to fgets anyway, except you can specify the ending char, so no surprise
#$strInput = trim(stream_get_line(STDIN, 1024, PHP_EOL));
$strInput = trim(fgets(STDIN, 1024));
var_dump($strInput);
}
Basically this works, but I have a problem if I type in any non ASCI character, then using backspace.
e.g. input = 'ß' // string(2) "ß"
e.g. input = 'ß' and backspace // string(1) "�"
e.g. input = 'ß' and backspace twice // string(0) ""
I don't know whether this a PHP or terminal problem. I tend to think it is a PHP problem. It works on my terminal:
e.g. % ß // ß: Command not found
e.g. % ßß and backspace // ß: Command not found
Unfortunatelly there is no mb_* function to read from STDIN.
Here are my terminal settings:
% locale
LANG=de_DE.UTF-8
LC_CTYPE="de_DE.UTF-8"
LC_COLLATE=C
LC_TIME="de_DE.UTF-8"
LC_NUMERIC="de_DE.UTF-8"
LC_MONETARY="de_DE.UTF-8"
LC_MESSAGES="de_DE.UTF-8"
LC_ALL=
% stty -a
speed 38400 baud; 58 rows; 212 columns;
lflags: icanon isig iexten echo echoe echok echoke -echonl echoctl
-echoprt -altwerase -noflsh -tostop -flusho -pendin -nokerninfo
-extproc
iflags: -istrip icrnl -inlcr -igncr ixon -ixoff ixany imaxbel -ignbrk
brkint -inpck -ignpar -parmrk
oflags: opost onlcr -ocrnl tab0 -onocr -onlret
cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -dsrflow
-dtrflow -mdmbuf
cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = <undef>;
eol2 = <undef>; erase = ^H; erase2 = ^H; intr = ^C; kill = ^U;
lnext = ^V; min = 1; quit = ^\; reprint = ^R; start = ^Q;
status = ^T; stop = ^S; susp = ^Z; time = 0; werase = ^W;
% cat /home/foobar/.login_conf
# $FreeBSD: releng/10.2/share/skel/dot.login_conf 77995 2001-06-10 17:08:53Z ache $
#
# see login.conf(5)
#
me:\
:charset=UTF-8:\
:lang=de_DE.UTF-8:\
:setenv=LC_COLLATE=C:
I am using FreeBSD 10.3 with the latest PHP 7.1.9. I also tried different shells like bash, but the output remains the same. Also tried starting xterm with -u8 option, no success.
Does anybody have an idea how to fix this? What am I missing?