35、PHP 原生魅力 - 字符串 - 验证数字字符串

作者: 温新

图书: 【原生 PHP 魅力】

阅读: 123

时间: 2024-09-08 00:03:46

当你需要验证一个包含数字的字符串时,如果输入字符串只包含数字,函数 ctype_digit() 返回 true:

<?php

$a = ctype_digit("123456789");
$b = ctype_digit("1234 A 56789");

var_dump($a);
var_dump($b);

输出如下:

$ php 35-ctype-digit.php
bool(true)
bool(false)
请登录后再评论