Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to type unicode characters in php cli

Tags:

php

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?

like image 417
ericj Avatar asked Dec 06 '25 03:12

ericj


2 Answers

You can do:

echo "\x20\xac";

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

like image 85
Sammitch Avatar answered Dec 07 '25 16:12

Sammitch


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
like image 21
Frank Avatar answered Dec 07 '25 16:12

Frank



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!