- rawurlencode: documentation ( source)
- str_replace: documentation ( source)
- htmlspecialchars: documentation ( source)
<?php
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";
}
}