Paste Unicode into PHP CLI

From FVue
Jump to: navigation, search

Problem

When I run php -a to run an interactive PHP shell, I can't paste special Unicode characters, e.g. when I try to paste "fóóbar" using the middle mouse button, what appears is "fbar":

$ php -a
Interactive shell
 
php ># fbar   # Pasting in php-cli goes wrong^C
$ # fóóbar  # Pasting in bash-shell goes all right

Environment

  • PHP 5.3.10-1ubuntu3.11 with Suhosin-Patch (cli)
  • Ubuntu 12.04
  • Konsole-2.8.5

Workaround

Create a separate php file and execute like:

$ cat - > t.php
<?php print 'fóóbar';
^D
$ php t.php
fóóbar

Journal

Tried suggestion from http://www.saturngod.net/articles/php-cli-with-unicode/ to change this:

--- /etc/php5/cli/php-orig.ini  2014-06-12 12:07:03.676734580 +0200
+++ /etc/php5/cli/php.ini       2014-06-12 13:25:56.948753261 +0200
@@ -782,6 +782,7 @@
 ; PHP's default character set is set to empty.
 ; http://php.net/default-charset
 ;default_charset = "iso-8859-1"
+default_charset = "UTF-8"
 
 ; Always populate the $HTTP_RAW_POST_DATA variable. PHP's default behavior is
 ; to disable this feature.
@@ -1727,6 +1728,7 @@
 ; (e.g. SJIS, BIG5, ISO-2022-*)
 ; http://php.net/mbstring.internal-encoding
 ;mbstring.internal_encoding = EUC-JP
+mbstring.internal_encoding = UTF-8
 
 ; http input encoding.
 ; http://php.net/mbstring.http-input

but to no avail :-(