<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>文字数と桁数をチェックしたい</title>
</head>
<body>
<?php
$example = @$_POST['example'];
if (strlen($example) > 0) {
if (ctype_digit($example)) {
echo '<p>「' . h($example) . '」は' . strlen($example) . '桁です。</p>';
} else {
echo '<p>「' . h($example) . '」は' . mb_strlen($example) . '文字です。</p>';
}
}
function h($string) {
return htmlspecialchars($string, ENT_QUOTES);
}
?>
<form method="post" action="">
<p>文字か数字を入力してください</p>
<input type="text" name="example" value="" />
<input type="submit" value="送信" />
</form>
</body>
</html>