ctype_digitは、「numeric string」がTRUE。「int / float / string」はFALSE

バリデーション > Ctype 文字タイプチェック

戻り値判定

 閲覧数:1438  投稿日:2016-01-01  更新日:2016-01-14  

戻り値判定
ctype_digit判定結果がTRUE
・numeric string

ctype_digit判定結果がFALSE
・int
・float
・string

具体例
・1 は FALSE
・'1' は TRUE


int
・数値
・1

float
・浮動小数点数
・1.0

numeric string
・数値形式文字列
・'1'
・"1"

string
・文字列
・'あ'
・"あ"


コード

$x = 1;
var_dump($x);
if (ctype_digit($x)){
    echo"・「ctype_digit」TRUE
";
}else{
    echo"・「ctype_digit」FALSE
";
}

$x = 3.14;
var_dump($x);
if (ctype_digit($x)){
    echo"・「ctype_digit」TRUE
";
}else{
    echo"・「ctype_digit」FALSE
";
}

$x = '文字列';
var_dump($x);
if (ctype_digit($x)){
    echo"・「ctype_digit」TRUE
";
}else{
    echo"・「ctype_digit」FALSE
";
}

$x = '1';
var_dump($x);
if (ctype_digit($x)){
    echo"・「ctype_digit」TRUE
";
}else{
    echo"・「ctype_digit」FALSE
";
}

$x = "1";
var_dump($x);
if (ctype_digit($x)){
    echo"・「ctype_digit」TRUE
";
}else{
    echo"・「ctype_digit」FALSE
";
}



結果

int(1)
・「ctype_digit」FALSE
float(3.14)
・「ctype_digit」FALSE
string(9) "文字列"
・「ctype_digit」FALSE
string(1) "1"
・「ctype_digit」TRUE
string(1) "1"
・「ctype_digit」TRUE



タグ


ctype_digit 


リンク


ctype_digit



ctype_digit / 数字だけを許可



類似度ページランキング
順位 ページタイトル抜粋 %
1 ctype_digitは、「numeric string」がTRUE。「int / float / string」はFALSE 54
2 is_intは、「int」がTRUE。「float / numeric string / string」はFALSE 51
3 is_numericは、「int / float / numeric string」がTRUE。「string」はFALSE 49
4 range関数 / 引数が「numeric string」→ 「int で構成された配列」を返す → ctype_digit「FALSE」 38
5 ctype_alnum / 英数字だけを許可 31
6 stdClassで、指摘キー毎の数をカウント後、新たなキー「count」として追加 / foreach 30
7 「input type="datetime-local"」で受け取った文字列をハイフンへ変更 29
8 「Fatal error」を発生させないuser定義count関数 29
9 array_count_values / 配列の要素が持つ値の出現回数をカウント 29
10 Smartyのテンプレートにincludeしたファイルを表示 28
11 Simple PHP BBCode Parser 28
12 文字列を「複数の区切り文字」で配列へ変換 / preg_split使用案。採用 27
13 include_pathを二箇所設定 27
14 stdClass を foreach 27
15 stdClassで、指摘キー毎の数をカウント後、新たなキー「count」として追加 / array_count_values(array_column()) 27
16 switch文判定 … 「in_array」「array_keys」 27
17 「Fatal error」のみを表示させるuser定義関数 26
18 ctype_digit / 数字だけを許可 26
19 「可変変数」 × 「配列要素を、文字列連結して表示」 … for文+implode 25
20 配列要素を、文字列連結して表示(元配列を上書) … foreach文+implode 25
2026/12/03 12:13 更新
週間人気ページランキング / 11-26 → 12-2
順位 ページタイトル抜粋 アクセス数
1 PHPコード 19
2 対象文字列へ対して、一致したすべての文字列を置換する標準関数 / str_replace | 文字列(テキスト処理) 4
2 MySQLのdatetime型カラムより取得した「月日文字列」先頭に0があった場合、削除 | 日付および時刻関連 4
3 文字列の中で変数展開される要件 | 文字列(テキスト処理) 2
3 平均値、分散、標準偏差、学力偏差値を求める | 統計 2
3 後ろから3文字削除 / 「18:00:00」→「18:00」 | 文字列(テキスト処理) 2
3 8桁の生年月日数字を分解 | 文字列(テキスト処理) 2
3 マテリアルカラーをランダムに3色取得 / 重複なし | 色 2
3 「半角スペースもしくは全角スペースで区切られた文字列」先頭に指定文字列を付与 | 文字列(テキスト処理) 2
3 可変変数(変数) カテゴリー 2
4 セッション カテゴリー 1
4 echo | タグ毎エントリー一覧 1
4 配列定数同士をarray_mergeで後ろに単純連結(キーは新たに振り直す) | 定数 1
4 特定のHTMLタグのみ(aタグは除く)表示を許可 | エスケープ処理 1
4 if文には括弧を付けた方が良い | 条件分岐 1
4 realpath(__DIR__) | パス 1
4 後ろから3文字取得 | 文字列(テキスト処理) 1
4 「Fatal error」を発生させないuser定義count関数 | 配列(型) 1
4 対象文字列を、文字数に応じて半分に分割後、それぞれを取得 | 文字列(テキスト処理) 1
4 現在WebページのURLパスを第2階層まで取得 | パス 1
2026/12/3 5:05 更新