如何在php cli中键入unicode字符

I work with php cli, so on the command line, on a Linux computer. I want to type in a unicode character. How do you do that?

Suppose the character is the euro sign.

In vim I do: ctrl-v shift-u 20ac Enter.

In bash I do: ctlr-shift-u 20ac Enter.

So how in the php cli?

You can do:

echo "\x20\xac";

To echo the raw bytes, but what gets displayed will depend on your terminal settings. Things get... complicated.

I'm going to assume you're talking about the PHP Interactive Shell.

Unfortunately the interactive shell has no concept of unicode. You have two options:

  • Entering/pasting the characters directly (some European keyboard layouts allow you to enter the Euro sign directly)
  • Entering the unicode bytes using escape sequences. For instance echo "\xE2\x82\xAc"; will get you a Euro sign