Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to input chinese characters in php cli?

Tags:

php

The chinese characters can be displayed and inputted on my LXTerminal.

root@hwy:/home/debian8# 中文    \\now to input chinese characters on my LXTerminal,it means  chinese characters can be inputted.
bash: 中文: command not found   \\ bash react the  chinese characters on my LXTerminal,it means  chinese characters can be displayed.    

The chinese characters can be inputted and displayed on my python shell.
enter image description here Now let's enter into php cli(or say php shell)

enter image description here

enter image description here The chinese characters disappeared when to click enter key.
it means that chinese characters can be displayed but can not be inputted on php cli mode.
How to make the chinese characters can be inputted on php cli mode?
And it is a verified fact that chinese characters can't be pasted into php cli too.
Maybe some mbstring attributes will be edited in /etc/php5/cli/php.ini?

Thank to bwoebi .Three facts added to go on my research.
1. Versions of libreadline and libedit.

root@hwy:/home/debian8# find /  -name   'libreadline*'
/lib/x86_64-linux-gnu/libreadline.so.6.3
/lib/x86_64-linux-gnu/libreadline.so.6


root@hwy:/home/debian8# find /  -name   'libedit*'
/usr/lib/x86_64-linux-gnu/libedit.so.2
/usr/lib/x86_64-linux-gnu/libedit.so.2.0.51
/usr/share/lintian/overrides/libedit2

2.root@hwy:/home/debian8# ldd "$(which php)"

linux-vdso.so.1 (0x00007ffd35e5c000)
libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007ff98ac68000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007ff98aa4d000)
libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007ff98a836000)
libonig.so.2 => /usr/lib/x86_64-linux-gnu/libonig.so.2 (0x00007ff98a5cc000)
libcrypto.so.1.0.0 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007ff98a1d0000)
libssl.so.1.0.0 => /usr/lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007ff989f6f000)
libdb-5.3.so => /usr/lib/x86_64-linux-gnu/libdb-5.3.so (0x00007ff989bae000)
libqdbm.so.14 => /usr/lib/libqdbm.so.14 (0x00007ff989961000)
libbz2.so.1.0 => /lib/x86_64-linux-gnu/libbz2.so.1.0 (0x00007ff989751000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007ff9894e3000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007ff9892db000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ff988fda000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff988dd6000)
libnsl.so.1 => /lib/x86_64-linux-gnu/libnsl.so.1 (0x00007ff988bbe000)
libxml2.so.2 => /usr/lib/x86_64-linux-gnu/libxml2.so.2 (0x00007ff988857000)
libgssapi_krb5.so.2 => /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2 (0x00007ff98860c000)
libkrb5.so.3 => /usr/lib/x86_64-linux-gnu/libkrb5.so.3 (0x00007ff988338000)
libk5crypto.so.3 => /usr/lib/x86_64-linux-gnu/libk5crypto.so.3 (0x00007ff988107000)
libcom_err.so.2 => /lib/x86_64-linux-gnu/libcom_err.so.2 (0x00007ff987f03000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff987b58000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff98793b000)
/lib64/ld-linux-x86-64.so.2 (0x00007ff98ae9f000)
liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007ff987718000)
libkrb5support.so.0 => /usr/lib/x86_64-linux-gnu/libkrb5support.so.0 (0x00007ff98750c000)
libkeyutils.so.1 => /lib/x86_64-linux-gnu/libkeyutils.so.1 (0x00007ff987308000)

3.Chinese characters on php7 -a
php7 was installed as
http://www.tecmint.com/install-and-compile-php-7-on-centos-7-and-debian-8/
Chinese characters can be displayed and inputed on php7 -a.

There is a new discovery!
It is the readline library on php7.

php7 -i |grep Readline
Readline Support => enabled
Readline library => 6.3

It is the EditLine wrapper on php5.

php -i |grep Readline
Readline Support => enabled
Readline library => EditLine wrapper

The problem is in half-solved status .
How to make my php5 to use Readline library 6.3 as php7 do ?
I don't want to compile my php5 again ,just to change the library?
Today i compile php5 in my virtualbox with command :

./configure \
--prefix=/usr/local/php5.6 \
--with-config-file-path=/usr/local/php5.6/etc \
--with-readline

Chinese characters can be inputted and displayed on php -a interactive mode.
It is unwise to remove current php5 and compile everything from the beginning.

find / -name 'readline.so*'
/usr/lib/php5/20131226/readline.so
/usr/lib/x86_64-linux-gnu/libreadline.so
/usr/lib/x86_64-linux-gnu/ruby/2.1.0/readline.so
/usr/lib/x86_64-linux-gnu/libguilereadline-v-18.so.18
/usr/lib/x86_64-linux-gnu/libguilereadline-v-18.so
/usr/lib/x86_64-linux-gnu/libguilereadline-v-18.so.18.0.0
/usr/lib/python2.7/lib-dynload/readline.x86_64-linux-gnu.so
/lib/x86_64-linux-gnu/libreadline.so.6.3
/lib/x86_64-linux-gnu/libreadline.so.6

Maybe to enable /lib/x86_64-linux-gnu/libreadline.so.6.3 ,how to make it work for my php5?

like image 565
showkey Avatar asked Aug 11 '16 08:08

showkey


1 Answers

php -a uses either libreadline or libedit as underlying libraries.

Inside the readline_shell_run() function in ext/readline/readline.c, PHP calls the readline() library function. So the problem doesn't lie in PHP itself, but in the library used.

On my OS X terminal [libedit 3.0.0] it works fine, pasting and passing to CLI.

So, to figure out the problem, what are you using libreadline? or libedit? (check version and library used with ldd "$(which php)") Research whether the version of libedit or libreadline your PHP installation uses has known bugs with the encoding of the terminal you're using.

If there are newer versions of the libraries, you might want trying to install these instead and check whether the issue is gone.

like image 196
bwoebi Avatar answered Nov 15 '22 12:11

bwoebi