암호 해독 가능한 사이트
function decode_utf8($str)
{
$code_point = 0;
$bytes_needed = 0;
$bytes_seen = 0;
$lower_boundary = 0x80;
$upper_boundary = 0xbf;
$code_points = array();
for ($i = 0, $len = strlen($str); $i < $len; $i++) {
$byte = ord($str[$i]);
if ($bytes_needed == 0) {
if ($byte >= 0x00 and $byte <= 0x7f) {
$code_points[] = $byte;
} elseif ($byte >= 0xc2 and $byte <= 0xdf) {
$bytes_needed = 1;
$code_point = $byte - 0xc0;
} elseif ($byte >= 0xe0 and $byte <= 0xef) {
if ($byte == 0xe0) {
$lower_boundary = 0xa0;
}
if ($byte == 0xed) {
$upper_boundary = 0x9f;
}
$bytes_needed = 2;
$code_point = $byte - 0xe0;
} elseif ($byte >= 0xf0 and $byte <= 0xf4) {
if ($byte == 0xf0) {
$lower_boundary = 0x90;
}
if ($byte == 0xf4) {
$upper_boundary = 0x8f;
}
$bytes_needed = 3;
$code_point = $byte - 0xf0;
} else {
return;
}
$code_point = $code_point << (6 * $bytes_needed);
continue;
}
if ($byte < $lower_boundary or $byte > $upper_boundary) {
return;
}
$lower_boundary = 0x80;
$upper_boundary = 0xbf;
$bytes_seen++;
$code_point += ($byte - 0x80) << (6 * ($bytes_needed - $bytes_seen));
if ($bytes_seen != $bytes_needed) {
continue;
}
$code_points[] = $code_point;
$code_point = 0;
$bytes_needed = 0;
$bytes_seen = 0;
}
if ($bytes_needed != 0) {
return;
}
return $code_points;
}
foreach (decode_utf8('미술') as $code_point) {
echo '\\u'.str_pad(dechex($code_point), $code_point>0xffff?6:4, '0', STR_PAD_LEFT);
}
----------------------------
https://www.php.net/manual/en/function.utf8-decode.php
utf8-decode는 8.2부터 DEPRECATED 되므로 아래와 같은 변환방식을 이용하시면 됩니다.
https://www.php.net/manual/en/function.mb-convert-encoding.php
-----------------------------
<?php
/* Convert internal character encoding to SJIS */
$str = mb_convert_encoding($str, "SJIS");
/* Convert EUC-JP to UTF-7 */
$str = mb_convert_encoding($str, "UTF-7", "EUC-JP");
/* Auto detect encoding from JIS, eucjp-win, sjis-win, then convert str to UCS-2LE */
$str = mb_convert_encoding($str, "UCS-2LE", "JIS, eucjp-win, sjis-win");
/* If mbstring.language is "Japanese", "auto" is expanded to "ASCII,JIS,UTF-8,EUC-JP,SJIS" */
$str = mb_convert_encoding($str, "EUC-JP", "auto");
?>