3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tai = '鯛'; // A kind of fish, included in JIS X 0208 $kasago = '鮋'; // A kind of fish, included in JIS X 0212, not included in JIS X 0213. $hokke = '𩸽'; // A kind of fish, included in JIS X 0213, not included in JIS X 0212. echo "# mb_convert_encoding\n"; $tai_iso2022jp = mb_convert_encoding($tai, 'ISO-2022-JP', 'UTF-8'); $tai_jis = mb_convert_encoding($tai, 'JIS', 'UTF-8'); $tai_iso2022jp_2004 = mb_convert_encoding($tai, 'ISO-2022-JP-2004', 'UTF-8'); echo "Convert tai to ISO-2022-JP : " . bin2hex($tai_iso2022jp) . "\n"; echo "Convert tai to JIS : " . bin2hex($tai_jis) . "\n"; echo "Convert tai to ISO-2022-JP-2004 : " . bin2hex($tai_iso2022jp_2004) . "\n"; echo "\n"; $kasago_iso2022jp = mb_convert_encoding($kasago, 'ISO-2022-JP', 'UTF-8'); $kasago_jis = mb_convert_encoding($kasago, 'JIS', 'UTF-8'); $kasago_iso2022jp_2004 = mb_convert_encoding($kasago, 'ISO-2022-JP-2004', 'UTF-8'); echo "Convert kasago to ISO-2022-JP : " . bin2hex($kasago_iso2022jp) . "\n"; echo "Convert kasago to JIS : " . bin2hex($kasago_jis) . "\n"; echo "Convert kasago to ISO-2022-JP-2004: " . bin2hex($kasago_iso2022jp_2004) . "\n"; echo "\n"; $hokke_iso2022jp = mb_convert_encoding($hokke, 'ISO-2022-JP', 'UTF-8'); $hokke_jis = mb_convert_encoding($hokke, 'JIS', 'UTF-8'); $hokke_iso2022jp_2004 = mb_convert_encoding($hokke, 'ISO-2022-JP-2004', 'UTF-8'); echo "Convert hokke to ISO-2022-JP : " . bin2hex($hokke_iso2022jp) . "\n"; echo "Convert hokke to JIS : " . bin2hex($hokke_jis) . "\n"; echo "Convert hokke to ISO-2022-JP-2004 : " . bin2hex($hokke_iso2022jp_2004) . "\n"; echo "\n"; echo "# mb_check_encoding\n"; $tai_0208 = mb_convert_encoding($tai, 'ISO-2022-JP', 'UTF-8'); // 1b244242641b2842 $kasago_0212 = mb_convert_encoding($kasago, 'JIS', 'UTF-8'); // 1b2428446a591b2842 $hokke_0213 = mb_convert_encoding($hokke, 'ISO-2022-JP-2004', 'UTF-8'); // 1b2428507d4c1b2842 echo "Tai written in JIS X 0208 : " . bin2hex($tai_0208) . "\n"; echo "Hokke written in JIS X 0212 : " . bin2hex($kasago_0212) . "\n"; echo "Kasago written in JIS X 0213: " . bin2hex($hokke_0213) . "\n"; echo "\n"; echo "Tai written in JIS X 0208\n"; echo "ISO-2022-JP : "; var_dump(mb_check_encoding($tai_0208, 'iso-2022-jp')); // true is expected echo "JIS : "; var_dump(mb_check_encoding($tai_0208, 'jis')); // true is expected echo "ISO-2022-JP-2004: "; var_dump(mb_check_encoding($tai_0208, 'iso-2022-jp-2004')); // true is expected echo "\n"; echo "Kasago written in JIS X 0212\n"; echo "ISO-2022-JP : "; var_dump(mb_check_encoding($kasago_0212, 'iso-2022-jp')); // false is expected echo "JIS : "; var_dump(mb_check_encoding($kasago_0212, 'jis')); // true is expected echo "ISO-2022-JP-2004: "; var_dump(mb_check_encoding($kasago_0212, 'iso-2022-jp-2004')); // false is expected echo "\n"; echo "Hokke written in JIS X 0213\n"; echo "ISO-2022-JP : "; var_dump(mb_check_encoding($hokke_0213, 'iso-2022-jp')); // false is expected echo "JIS : "; var_dump(mb_check_encoding($hokke_0213, 'jis')); // false is expected echo "ISO-2022-JP-2004: "; var_dump(mb_check_encoding($hokke_0213, 'iso-2022-jp-2004')); // true is expected

preferences:
49.66 ms | 407 KiB | 5 Q