Php-function-ctype-digit
提供:Dev Guides
PHP-関数ctype_digit()
構文
ctype_digit ( $text );
定義と使い方
指定された文字列、テキスト内のすべての文字が数字であるかどうかをチェックします。 1 … 9のみをチェックします
パラメーター
Sr.No | Parameter & Description |
---|---|
1 |
text(Required) テストされた文字列。 |
戻り値
テキスト内のすべての文字が10進数の場合はTRUE、そうでない場合はFALSEを返します。
例
次の例を試してください-
<?php
$strings = array('122.50', '1004', 'foo!#$bar');
foreach ($strings as $test) {
if (ctype_digit($test)) {
echo "$test consists of all digits. \n";
}else {
echo "$test does not have all digits. \n";
}
}
?>
これは、次の結果を生成します-
122.50 does not have all digits
1004 consists of all digits
foo!#$bar does not have all digits