¥«¥¹¥¿¥à¥«¡¼¸¡º÷·ë²Ì[£Î£É£Ó£Ó£Á£Î]
[¸¡º÷·ë²Ì] Á´12·ïÃæ 1·ïÌÜ¡Á12·ïÌܤòɽ¼¨[1/1¥Ú¡¼¥¸]
0xEF) return 1; if($b[2] < 0x80) return 2; if($b[2] > 0xFC) return 1; if($is_utf8){ if(0xDF < $b[1] && $b[1] < 0xF0){ if( (0x7F < $b[2] && $b[2] < 0xC0) && (0x7F < $b[3] && $b[3] < 0xC0) ){ return 4; }else{ $is_utf8 = FALSE; } }elseif( !(0x7F < $b[2] && $b[2] < 0xC0) ){ return 1; } }elseif(0xBF < $b[1] && $b[1] < 0xE0){ return 1; } $i++; } if($is_ascii) return 0; return 5;}function HANtoZEN($str, $encode){ //0:PASS //1:EUC-JP //2:Shift_JIS //3:ISO-2022-JP(JIS) //4:UTF-8 if($encode == 0) return $str; if($encode == 1) return HANtoZEN_EUC($str); if($encode == 2) return HANtoZEN_SJIS($str); if($encode == 3) return HANtoZEN_JIS($str); if($encode == 4) return HANtoZEN_UTF8($str); return $str;}function JIStoSJIS($str_JIS){ $str_SJIS = ''; $mode = 0; $b = unpack("C*", $str_JIS); $n = count($b); for($i = 1; $i <= $n; $i++){ if($b[$i] == 0x1B){ if(($b[$i+1] == 0x24 && $b[$i+2] == 0x42) || ($b[$i+1] == 0x24 && $b[$i+2] == 0x40)){ $mode = 1; }elseif($b[$i+1] == 0x28 && $b[$i+2] == 0x49){ $mode = 2; }else{ $mode = 0; } $i += 3; } if($mode == 1){ if($b[$i] & 0x01){ $b[$i] >>= 1; if($b[$i] < 0x2F) $b[$i] += 0x71; else $b[$i] -= 0x4F; if($b[$i+1] > 0x5F) $b[$i+1] += 0x20; else $b[$i+1] += 0x1F; }else{ $b[$i] >>= 1; if($b[$i] <= 0x2F) $b[$i] += 0x70; else $b[$i] -= 0x50; $b[$i+1] += 0x7E; } $str_SJIS .= pack("CC", $b[$i], $b[$i+1]); $i++; }elseif($mode == 2){ $b[$i] += 0x80; $str_SJIS .= pack("C", $b[$i]); }else{ $str_SJIS .= pack("C", $b[$i]); } } return $str_SJIS;}function JIStoEUC($str_JIS){ $str_EUC = ''; $mode = 0; $b = unpack("C*", $str_JIS); $n = count($b); for($i = 1; $i <= $n; $i++){ if($b[$i] == 0x1B){ if(($b[$i+1] == 0x24 && $b[$i+2] == 0x42) || ($b[$i+1] == 0x24 && $b[$i+2] == 0x40)){ $mode = 1; }elseif(($b[$i+1] == 0x28 && $b[$i+2] == 0x49)){ $mode = 2; }else{ $mode = 0; } $i += 3; } if($mode == 1){ $b[$i] += 0x80; $b[$i+1] += 0x80; $str_EUC .= pack("CC", $b[$i], $b[$i+1]); $i++; }elseif($mode == 2){ $b[$i] += 0x80; $str_EUC .= pack("CC", 0x8E, $b[$i]); }else{ $str_EUC .= pack("C", $b[$i]); } } return $str_EUC;}function SJIStoJIS($str_SJIS){ $str_JIS = ''; $mode = 0; $b = unpack("C*", $str_SJIS); $n = count($b); for($i = 1; $i <= $n; $i++){ if(0xA1 <= $b[$i] && $b[$i] <= 0xDF){ if($mode != 2){ $mode = 2; $str_JIS .= pack("CCC", 0x1B, 0x28, 0x49); } $b[$i] -= 0x80; $str_JIS .= pack("C", $b[$i]); }elseif($b[$i] >= 0x80){ if($mode != 1){ $mode = 1; $str_JIS .= pack("CCC", 0x1B, 0x24, 0x42); } $b[$i] <<= 1; if($b[$i+1] < 0x9F){ if($b[$i] < 0x13F) $b[$i] -= 0xE1; else $b[$i] -= 0x61; if($b[$i+1] > 0x7E) $b[$i+1] -= 0x20; else $b[$i+1] -= 0x1F; }else{ if($b[$i] < 0x13F) $b[$i] -= 0xE0; else $b[$i] -= 0x60; $b[$i+1] -= 0x7E; } $b[$i] = $b[$i] & 0xff; $str_JIS .= pack("CC", $b[$i], $b[$i+1]); $i++; }else{ if($mode != 0){ $mode = 0; $str_JIS .= pack("CCC", 0x1B, 0x28, 0x42); } $str_JIS .= pack("C", $b[$i]); } } if($mode != 0) $str_JIS .= pack("CCC", 0x1B, 0x28, 0x42); return $str_JIS;}function SJIStoEUC($str_SJIS){ $str_EUC = ''; $b = unpack("C*", $str_SJIS); $n = count($b); for($i = 1; $i <= $n; $i++){ if(0xA1 <= $b[$i] && $b[$i] <= 0xDF){ $str_EUC .= pack("CC", 0x8E, $b[$i]); }elseif($b[$i] >= 0x81){ $b[$i] <<= 1; if($b[$i+1] < 0x9F){ if($b[$i] < 0x13F) $b[$i] -= 0x61; else $b[$i] -= 0xE1; if($b[$i+1] > 0x7E) $b[$i+1] += 0x60; else $b[$i+1] += 0x61; }else{ if($b[$i] < 0x13F) $b[$i] -= 0x60; else $b[$i] -= 0xE0; $b[$i+1] += 0x02; } $str_EUC .= pack("CC", $b[$i], $b[$i+1]); $i++; }else{ $str_EUC .= pack("C", $b[$i]); } } return $str_EUC;}function EUCtoJIS($str_EUC){ $str_JIS = ''; $mode = 0; $b = unpack("C*", $str_EUC); $n = count($b); for($i = 1; $i <= $n; $i++){ if($b[$i] == 0x8E){ if($mode != 2){ $mode = 2; $str_JIS .= pack("CCC", 0x1B, 0x28, 0x49); } $b[$i+1] -= 0x80; $str_JIS .= pack("C", $b[$i+1]); $i++; }elseif($b[$i] > 0x8E){ if($mode != 1){ $mode = 1; $str_JIS .= pack("CCC", 0x1B, 0x24, 0x42); } $b[$i] -= 0x80; $b[$i+1] -= 0x80; $str_JIS .= pack("CC", $b[$i], $b[$i+1]); $i++; }else{ if($mode != 0){ $mode = 0; $str_JIS .= pack("CCC", 0x1B, 0x28, 0x42); } $str_JIS .= pack("C", $b[$i]); } } if($mode != 0) $str_JIS .= pack("CCC", 0x1B, 0x28, 0x42); return $str_JIS;}function EUCtoSJIS($str_EUC){ $str_SJIS = ''; $b = unpack("C*", $str_EUC); $n = count($b); for($i = 1; $i <= $n; $i++){ if($b[$i] == 0x8E){ $str_SJIS .= pack("C", $b[$i+1]); $i++; }elseif($b[$i] >= 0x80){ if($b[$i] & 0x01){ $b[$i] >>= 1; if($b[$i] < 0x6F) $b[$i] += 0x31; else $b[$i] += 0x71; if($b[$i+1] > 0xDF) $b[$i+1] -= 0x60; else $b[$i+1] -= 0x61; }else{ $b[$i] >>= 1; if($b[$i] <= 0x6F) $b[$i] += 0x30; else $b[$i] += 0x70; $b[$i+1] -= 0x02; } $str_SJIS .= pack("CC", $b[$i], $b[$i+1]); $i++; }else{ $str_SJIS .= pack("C", $b[$i]); } } return $str_SJIS;}function SJIStoUTF8($str_SJIS){ global $table_jis2ucs; $str_UTF8 = ""; $b = unpack("C*", $str_SJIS); $n = count($b); for($i = 1; $i <= $n; $i++){ if(0xA1 <= $b[$i] && $b[$i] <= 0xDF){ $b2 = $b[$i] - 0x40; $b1 = 0xFF; $u1 = 0xE0 | (($b1 >> 4) & 0x0f); $u2 = 0x80 | (($b1 << 2) & 0x3c) | (($b2 >> 6) & 0x03); $u3 = 0x80 | ($b2 & 0x3f); $str_UTF8 .= pack("CCC", $u1, $u2, $u3); }elseif($b[$i] >= 0x80){ $b[$i] <<= 1; if($b[$i+1] < 0x9F){ if($b[$i] < 0x13F) $b[$i] -= 0xE1; else $b[$i] -= 0x61; if($b[$i+1] > 0x7E) $b[$i+1] -= 0x20; else $b[$i+1] -= 0x1F; }else{ if($b[$i] < 0x13F) $b[$i] -= 0xE0; else $b[$i] -= 0x60; $b[$i+1] -= 0x7E; } $b[$i] = $b[$i] & 0xff; $data = ($b[$i] << 8) + $b[$i+1] - 0x2120; for($j = 0; $j < $data; $j++){ if(($j*256 <= $data) && ($data <= $j*256+94)) break; } if(!isset($table_jis2ucs[$data-162*$j-1])) $b0 = 0; else $b0 = $table_jis2ucs[$data-162*$j-1]; $b1 = ($b0 & 0xff00) >> 8; $b2 = $b0 & 0x00ff; $u1 = 0xE0 | (($b1 >> 4) & 0x0f); $u2 = 0x80 | (($b1 << 2) & 0x3c) | (($b2 >> 6) & 0x03); $u3 = 0x80 | ($b2 & 0x3f); $str_UTF8 .= pack("CCC", $u1, $u2, $u3); $i++; }else{ $str_UTF8 .= pack("C", $b[$i]); } } return $str_UTF8;}function EUCtoUTF8($str_EUC){ global $table_jis2ucs; $str_UTF8 = ""; $b = unpack("C*", $str_EUC); $n = count($b); for($i = 1; $i <= $n; $i++){ if($b[$i] == 0x8E){ $b2 = $b[$i+1] - 0x40; $b1 = 0xFF; $u1 = 0xE0 | (($b1 >> 4) & 0x0f); $u2 = 0x80 | (($b1 << 2) & 0x3c) | (($b2 >> 6) & 0x03); $u3 = 0x80 | ($b2 & 0x3f); $str_UTF8 .= pack("CCC", $u1, $u2, $u3); $i++; }elseif($b[$i] >= 0x80){ $b[$i] -= 0x80; $b[$i+1] -= 0x80; $data = ($b[$i] << 8) + $b[$i+1] - 0x2120; for($j = 0; $j < $data; $j++){ if(($j*256 <= $data) && ($data <= $j*256+94)) break; } if(!isset($table_jis2ucs[$data-162*$j-1])) $b0 = 0; else $b0 = $table_jis2ucs[$data-162*$j-1]; $b1 = ($b0 & 0xff00) >> 8; $b2 = $b0 & 0x00ff; $u1 = 0xE0 | (($b1 >> 4) & 0x0f); $u2 = 0x80 | (($b1 << 2) & 0x3c) | (($b2 >> 6) & 0x03); $u3 = 0x80 | ($b2 & 0x3f); $str_UTF8 .= pack("CCC", $u1, $u2, $u3); $i++; }else{ $str_UTF8 .= pack("C", $b[$i]); } } return $str_UTF8;}function JIStoUTF8($str_JIS){ global $table_jis2ucs; $str_UTF8 = ""; $mode = 0; $b = unpack("C*", $str_JIS); $n = count($b); for($i = 1; $i <= $n; $i++){ if($b[$i] == 0x1B){ if(($b[$i+1] == 0x24 && $b[$i+2] == 0x42) || ($b[$i+1] == 0x24 && $b[$i+2] == 0x40)){ $mode = 1; }elseif($b[$i+1] == 0x28 && $b[$i+2] == 0x49){ $mode = 2; }else{ $mode = 0; } $i += 3; $b1 = unpack("C*", substr($str_JIS, $i, 1)); } if($mode == 1){ $data = ($b[$i] << 8) + $b[$i+1] - 0x2120; for($j = 0; $j < $data; $j++){ if(($j*256 <= $data) && ($data <= $j*256+94)) break; } if(!isset($table_jis2ucs[$data-162*$j-1])) $b0 = 0; else $b0 = $table_jis2ucs[$data-162*$j-1]; $b1 = ($b0 & 0xff00) >> 8; $b2 = $b0 & 0x00ff; $u1 = 0xE0 | (($b1 >> 4) & 0x0f); $u2 = 0x80 | (($b1 << 2) & 0x3c) | (($b2 >> 6) & 0x03); $u3 = 0x80 | ($b2 & 0x3f); $str_UTF8 .= pack("CCC", $u1, $u2, $u3); $i++; }elseif($mode == 2){ $b2 = $b[$i] + 0x40; $b1 = 0xFF; $u1 = 0xE0 | (($b1 >> 4) & 0x0f); $u2 = 0x80 | (($b1 << 2) & 0x3c) | (($b2 >> 6) & 0x03); $u3 = 0x80 | ($b2 & 0x3f); $str_UTF8 .= pack("CCC", $u1, $u2, $u3); }else{ $str_UTF8 .= pack("C", $b[$i]); } } return $str_UTF8;}function UTF8toSJIS($str_UTF8){ global $table_ucs2jis; $str_SJIS = ""; $b = unpack("C*", $str_UTF8); $n = count($b); for($i = 1; $i <= $n; $i++){ if($b[$i] >= 0x80){ if(($b[$i] & 0xE0) == 0xC0){ $u1 = (($b[$i] >> 2) & 0x07) & 0x07; $u2 = (($b[$i] << 6) & 0xC0) | ($b[$i+1] & 0x3F); $i++; }elseif(($b[$i] & 0xF0) == 0xE0){ $u1 = (($b[$i] << 4) & 0xF0) | (($b[$i+1] >> 2) & 0x0F); $u2 = (($b[$i+1] << 6) & 0xC0) | ($b[$i+2] & 0x3F); $i += 2; } if($u1 == 0xFF && (0x61 <= $u2 && $u2 <= 0x9F)){ $c1 = $u2 + 0x40; $str_SJIS .= pack("C", $c1); }else{ if(!isset($table_ucs2jis[($u1 << 8) + $u2])) $index = 0; else $index = $table_ucs2jis[($u1 << 8) + $u2]; $c1 = ($index & 0xFF00) >> 8; $c2 = $index & 0x00FF; if($c1 & 0x01){ $c1 >>= 1; if($c1 < 0x2F) $c1 += 0x71; else $c1 -= 0x4F; if($c2 > 0x5F) $c2 += 0x20; else $c2 += 0x1F; }else{ $c1 >>= 1; if($c1 < 0x2F) $c1 += 0x70; else $c1 -= 0x50; $c2 += 0x7E; } $str_SJIS .= pack("CC", $c1, $c2); } }else{ $c1 = $table_ucs2jis[$b[$i]]; $str_SJIS .= pack("C", $c1); } } return $str_SJIS;}function UTF8toEUC($str_UTF8){ global $table_ucs2jis; $str_EUC = ""; $b = unpack("C*", $str_UTF8); $n = count($b); for($i = 1; $i <= $n; $i++){ if($b[$i] >= 0x80){ if(($b[$i] & 0xE0) == 0xC0){ $u1 = (($b[$i] >> 2) & 0x07) & 0x07; $u2 = (($b[$i] << 6) & 0xC0) | ($b[$i+1] & 0x3F); $i++; }elseif(($b[$i] & 0xF0) == 0xE0){ $u1 = (($b[$i] << 4) & 0xF0) | (($b[$i+1] >> 2) & 0x0F); $u2 = (($b[$i+1] << 6) & 0xC0) | ($b[$i+2] & 0x3F); $i += 2; } if($u1 == 0xFF && (0x61 <= $u2 && $u2 <= 0x9F)){ $c1 = 0x8E; $c2 = $u2 + 0x40; }else{ if(!isset($table_ucs2jis[($u1 << 8) + $u2])) $index = 0; else $index = $table_ucs2jis[($u1 << 8) + $u2]; $c1 = ($index & 0xFF00) >> 8; $c2 = $index & 0x00FF; $c1 += 0x80; $c2 += 0x80; } $str_EUC .= pack("CC", $c1, $c2); }else{ $c1 = $table_ucs2jis[$b[$i]]; $str_EUC .= pack("C", $c1); } } return $str_EUC;}function UTF8toJIS($str_UTF8){ global $table_ucs2jis; $str_JIS = ""; $mode = 0; $b = unpack("C*", $str_UTF8); $n = count($b); for($i = 1; $i <= $n; $i++){ if($b[$i] >= 0x80){ if(($b[$i] & 0xE0) == 0xC0){ $u1 = (($b[$i] >> 2) & 0x07) & 0x07; $u2 = (($b[$i] << 6) & 0xC0) | ($b[$i+1] & 0x3F); $i++; }elseif(($b[$i] & 0xF0) == 0xE0){ $u1 = (($b[$i] << 4) & 0xF0) | (($b[$i+1] >> 2) & 0x0F); $u2 = (($b[$i+1] << 6) & 0xC0) | ($b[$i+2] & 0x3F); $i += 2; } if($u1 == 0xFF && (0x61 <= $u2 && $u2 <= 0x9F)){ if($mode != 2){ $mode = 2; $str_JIS .= pack("CCC", 0x1B, 0x28, 0x49); } $c1 = $u2 - 0x40; $str_JIS .= pack("C", $c1); }else{ if($mode != 1){ $mode = 1; $str_JIS .= pack("CCC", 0x1B, 0x24, 0x42); } if(!isset($table_ucs2jis[($u1 << 8) + $u2])) $index = 0; else $index = $table_ucs2jis[($u1 << 8) + $u2]; $c1 = ($index & 0xFF00) >> 8; $c2 = $index & 0x00FF; $str_JIS .= pack("CC", $c1, $c2); } }else{ if($mode != 0){ $mode = 0; $str_JIS .= pack("CCC", 0x1B, 0x28, 0x42); } $c1 = $table_ucs2jis[$b[$i]] & 0x00FF; $str_JIS .= pack("C", $c1); } } if($mode != 0) $str_JIS .= pack("CCC", 0x1B, 0x28, 0x42); return $str_JIS;}function HANtoZEN_EUC($str_HAN){ $table_han2zen_euc = array(0xA1A3,0xA1D6,0xA1D7,0xA1A2,0xA1A6,0xA5F2, 0xA5A1,0xA5A3,0xA5A5,0xA5A7,0xA5A9,0xA5E3,0xA5E5,0xA5E7,0xA5C3,0xA1BC, 0xA5A2,0xA5A4,0xA5A6,0xA5A8,0xA5AA,0xA5AB,0xA5AD,0xA5AF,0xA5B1,0xA5B3, 0xA5B5,0xA5B7,0xA5B9,0xA5BB,0xA5BD,0xA5BF,0xA5C1,0xA5C4,0xA5C6,0xA5C8, 0xA5CA,0xA5CB,0xA5CC,0xA5CD,0xA5CE,0xA5CF,0xA5D2,0xA5D5,0xA5D8,0xA5DB, 0xA5DE,0xA5DF,0xA5E0,0xA5E1,0xA5E2,0xA5E4,0xA5E6,0xA5E8,0xA5E9,0xA5EA, 0xA5EB,0xA5EC,0xA5ED,0xA5EF,0xA5F3,0xA1AB,0xA1AC); $str_ZEN = ''; $b = unpack("C*", $str_HAN); $n = count($b); for($i = 1; $i <= $n; $i++){ if($b[$i] == 0x8E){ $b[$i+1] -= 0xA1; $c1 = (($table_han2zen_euc[$b[$i+1]] & 0xff00) >> 8); $c2 = ($table_han2zen_euc[$b[$i+1]] & 0x00ff); $str_ZEN .= pack("CC", $c1, $c2); $i++; }elseif($b[$i] >= 0xA1){ $str_ZEN .= pack("CC", $b[$i], $b[$i+1]); $i++; }else{ $str_ZEN .= pack("C", $b[$i]); } } return $str_ZEN;}function HANtoZEN_SJIS($str_HAN){ $table_han2zen_sjis = array(0x8142,0x8175,0x8176,0x8141,0x8145,0x8392, 0x8340,0x8342,0x8344,0x8346,0x8348,0x8383,0x8385,0x8387,0x8362,0x815B, 0x8341,0x8343,0x8345,0x8347,0x8349,0x834A,0x834C,0x834E,0x8350,0x8352, 0x8354,0x8356,0x8358,0x835A,0x835C,0x835E,0x8360,0x8363,0x8365,0x8367, 0x8369,0x836A,0x836B,0x836C,0x836D,0x836E,0x8371,0x8374,0x8377,0x837A, 0x837D,0x837E,0x8380,0x8381,0x8382,0x8384,0x8386,0x8388,0x8389,0x838A, 0x838B,0x838C,0x838D,0x838F,0x8393,0x814A,0x814B); $str_ZEN = ''; $b = unpack("C*", $str_HAN); $n = count($b); for($i = 1; $i <= $n; $i++){ if(0xA1 <= $b[$i] && $b[$i] <= 0xDF){ $b[$i] -= 0xA1; $c1 = ($table_han2zen_sjis[$b[$i]] & 0xff00) >> 8; $c2 = $table_han2zen_sjis[$b[$i]] & 0x00ff; $str_ZEN .= pack("CC", $c1, $c2); }elseif($b[$i] >= 0x80){ $str_ZEN .= pack("CC", $b[$i], $b[$i+1]); $i++; }else{ $str_ZEN .= pack("C", $b[$i]); } } return $str_ZEN;}function HANtoZEN_JIS($str_HAN){ $table_han2zen_jis = array(0x2123,0x2156,0x2157,0x2122,0x2126,0x2572, 0x2521,0x2523,0x2525,0x2527,0x2529,0x2563,0x2565,0x2567,0x2543,0x213C, 0x2522,0x2524,0x2526,0x2528,0x252A,0x252B,0x252D,0x252F,0x2531,0x2533, 0x2535,0x2537,0x2539,0x253B,0x253D,0x253F,0x2541,0x2544,0x2546,0x2548, 0x254A,0x254B,0x254C,0x254D,0x254E,0x254F,0x2552,0x2555,0x2558,0x255B, 0x255E,0x255F,0x2560,0x2561,0x2562,0x2564,0x2566,0x2568,0x2569,0x256A, 0x256B,0x256C,0x256D,0x256F,0x2573,0x212B,0x212C); $str_ZEN = ''; $mode = 0; $b = unpack("C*", $str_HAN); $n = count($b); for($i = 1; $i <= $n; $i++){ if($b[$i] == 0x1B){ if($b[$i+1] == 0x28 && $b[$i+2] == 0x49){ $mode = 1; $str_ZEN .= pack("CCC", 0x1B, 0x24, 0x42); }else{ $mode = 0; $str_ZEN .= pack("CCC", $b[$i], $b[$i+1], $b[$i+2]); } $i += 3; } if($mode == 1){ $b[$i] -= 0x21; $c1 = ($table_han2zen_jis[$b[$i]] & 0xff00) >> 8; $c2 = $table_han2zen_jis[$b[$i]] & 0x00ff; $str_ZEN .= pack("CC", $c1, $c2); }else{ $str_ZEN .= pack("C", $b[$i]); } } return $str_ZEN;}function HANtoZEN_UTF8($str_HAN){ $table_han2zen_utf8_1 = array(0xE38082,0xE3808C,0xE3808D,0xE38081,0xE383BB, 0xE383B2,0xE382A1,0xE382A3,0xE382A5,0xE382A7,0xE382A9,0xE383A3,0xE383A5, 0xE383A7,0xE38383,0xE383BC,0xE382A2,0xE382A4,0xE382A6,0xE382A8,0xE382AA, 0xE382AB,0xE382AD,0xE382AF,0xE382B1,0xE382B3,0xE382B5,0xE382B7,0xE382B9, 0xE382BB,0xE382BD); $table_han2zen_utf8_2 = array(0xE382BF,0xE38381,0xE38384,0xE38386,0xE38388, 0xE3838A,0xE3838B,0xE3838C,0xE3838D,0xE3838E,0xE3838F,0xE38392,0xE38395, 0xE38398,0xE3839B,0xE3839E,0xE3839F,0xE383A0,0xE383A1,0xE383A2,0xE383A4, 0xE383A6,0xE383A8,0xE383A9,0xE383AA,0xE383AB,0xE383AC,0xE383AD,0xE383AF, 0xE383B3,0xE3829B,0xE3829C); $str_ZEN = ""; $b = unpack("C*", $str_HAN); $n = count($b); for($i = 1; $i <= $n; $i++){ if($b[$i] >= 0x80){ if(($b[$i] & 0xE0) == 0xC0){ $str_ZEN .= pack("CC", $b[$i], $b[$i+1]); $i++; }elseif(($b[$i] & 0xF0) == 0xE0){ if($b[$i+1] == 0xBD && (0xA1 <= $b[$i+2] && $b[$i+2] <= 0xBF)){ $zen = $table_han2zen_utf8_1[$b[$i+2] - 0xA1]; $b[$i] = ($zen & 0xFF0000) >> 16; $b[$i+1] = ($zen & 0x00FF00) >> 8; $b[$i+2] = $zen & 0x0000FF; }elseif($b[$i+1] == 0xBE &&(0x80 <= $b[$i+2] && $b[$i+2] <= 0x9F)){ $zen = $table_han2zen_utf8_2[$b[$i+2] - 0x80]; $b[$i] = ($zen & 0xFF0000) >> 16; $b[$i+1] = ($zen & 0x00FF00) >> 8; $b[$i+2] = $zen & 0x0000FF; } $str_ZEN .= pack("CCC", $b[$i], $b[$i+1], $b[$i+2]); $i += 2; } }else{ $str_ZEN .= pack("C", $b[$i]); } } return $str_ZEN;}?>
|