Skip to content

Instantly share code, notes, and snippets.

@jm42
Created October 4, 2014 17:47
Show Gist options
  • Save jm42/11fd47dd19e1484bd3e9 to your computer and use it in GitHub Desktop.
Save jm42/11fd47dd19e1484bd3e9 to your computer and use it in GitHub Desktop.
Test UTF-8
<?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