ericj
ericj

Reputation: 2291

How to type unicode characters in php cli

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?

Upvotes: 3

Views: 1781

Answers (2)

Frank
Frank

Reputation: 11

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

Upvotes: 1

Sammitch
Sammitch

Reputation: 32262

You can do:

echo "\x20\xac";

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

Upvotes: 1

Related Questions