<?php
function validate_utf8() {
return (bool)preg_match('//u', serialize(func_get_args()));
}
function test($input) {
$output = htmlspecialchars($input, ENT_QUOTES, 'UTF-8');
$code = str_replace('%', '\\x', rawurlencode($input));
if (validate_utf8($input)) {
echo "【{$output}】({$code}) は有効なUTF-8シーケンスです。\n";
} else {
echo "({$code}) は無効なUTF-8シーケンスです。\n";
}
}
test("☝( ◠‿◠ )☝");
test("ゔ〲〰");
test("\x0a\x92\xff"); // てきとー
test("\xef\xbb\xbf"); // BOMだっけ
test(""); // 空文字
echo "\n";
test("\x2f"); // スラッシュ(1バイト)
test("\xc0\xaf"); // スラッシュ(冗長2バイト)
test("\xe0\x80\xaf"); // スラッシュ(冗長3バイト)
test("\xf0\x80\x80\xaf"); // スラッシュ(冗長4バイト)
- Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.26, 8.2.0 - 8.2.13, 8.3.0
- 【☝( ◠‿◠ )☝】(\xE2\x98\x9D\x28\x20\xE2\x97\xA0\xE2\x80\xBF\xE2\x97\xA0\x20\x29\xE2\x98\x9D) は有効なUTF-8シーケンスです。
【ゔ〲〰】(\xE3\x82\x94\xE3\x80\xB2\xE3\x80\xB0) は有効なUTF-8シーケンスです。
(\x0A\x92\xFF) は無効なUTF-8シーケンスです。
【】(\xEF\xBB\xBF) は有効なUTF-8シーケンスです。
【】() は有効なUTF-8シーケンスです。
【/】(\x2F) は有効なUTF-8シーケンスです。
(\xC0\xAF) は無効なUTF-8シーケンスです。
(\xE0\x80\xAF) は無効なUTF-8シーケンスです。
(\xF0\x80\x80\xAF) は無効なUTF-8シーケンスです。
- Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.1 - 5.1.6, 5.2.0 - 5.2.17
- Fatal error: func_get_args(): Can't be used as a function parameter in /in/pVCpj on line 3
Process exited with code 255. - Output for 5.1.0
- Fatal error: fatal flex scanner internal error--end of buffer missed in /in/pVCpj on line 28
Process exited with code 255. - Output for 4.3.0 - 4.3.1
Process exited with code 139.
preferences:
172.55 ms | 402 KiB | 372 Q