utf 8 - PHP: chr Function Issue with Special characters -
in php have following code:
<?php echo "€<br>"; echo ord("€") . "<br>"; echo chr(128) . "<br>";
and following output:
€ 128 �
why can't chr function provide me € sign? how can €? need work. thank's in advance.
chr
, ord
work single byte ascii characters. more ord
looks @ first byte of parameter.
the euro sign 3 byte character in utf-8: 0xe2 0x82 0xac
, ord("€")
(with utf-8 symbol) returns 226 (0xe2)
for characters present in iso-8859-1 (latin1) character set, can use utf8_encode()
, utf8_decode()
, unfortunately € sign not contained there, utf8_decode('€')
return "?" , cannot converted back.
tl;dr: cannot use ord
, chr
multi-byte encoding utf-8
Comments
Post a Comment