Created
October 4, 2014 17:47
-
-
Save jm42/11fd47dd19e1484bd3e9 to your computer and use it in GitHub Desktop.
Test UTF-8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $tests = array( | |
| array(195, 169), // é | |
| array(227, 130, 171), // カ | |
| array(208, 150), // Ж | |
| ); | |
| function unichr($inte) { | |
| return mb_convert_encoding('&#' . intval($inte) . ';', 'UTF-8', 'HTML-ENTITIES'); | |
| } | |
| function bytearray($str) { | |
| return unpack('C*', $str); | |
| } | |
| function strfrombytearray(array $array) { | |
| return call_user_func_array('pack', array_merge(array('C*'), $array)); | |
| } | |
| //var_dump(unichr($b[0])); | |
| //var_dump(unichr($b[1])); | |
| //var_dump(unichr($b[0] + $b[1])); | |
| //var_dump(chr($b[0])); | |
| //var_dump(chr($b[1])); | |
| //var_dump('é'); | |
| //var_dump(ord('é')); | |
| //var_dump(chr(ord('é'))); | |
| //foreach ($b as $c) { | |
| // var_dump(dechex($c)); | |
| //} | |
| //var_dump(bytearray('é')); | |
| //var_dump(strfrombytearray(bytearray('é'))); | |
| //printf("%02X", 195); | |
| //printf("%02X", 169); | |
| header('Content-Type: text/html; charset=UTF-8'); | |
| foreach ($tests as $test) { | |
| print(strfrombytearray($test)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment