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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -