chr
and ord
only work with single byte ASCII characters. More specifically ord
only looks at the first byte of its parameter.
The Euro sign is a three byte character in UTF-8: 0xE2 0x82 0xAC
, so ord("€")
(with the UTF-8 symbol) returns 226 (0xE2)
For characters that are also present in the ISO-8859-1 (latin1) character set, you can use utf8_encode()
and utf8_decode()
, but unfortunately the € sign is not contained there, so utf8_decode('€')
will return "?" and cannot be converted back.
TL;DR: You cannot use ord
and chr
with a multi-byte encoding like UTF-8
ord('€')
returns226
instead of128
(the latter is the Latin 1 decimal code) – Thorman