Home >Backend Development >PHP Problem >How to judge whether php is a number
In PHP, you can use the "is_numeric()" function to determine whether the parameter is a number. If so, it will return true. If not, it will return false. Its syntax is such as "is_numeric('abcd123') or die(' The supplied argument is not a number ');".
php determines whether it is a number
There are two methods
First First: Use a function directly, is_numeric(). This function is to detect whether the parameter is a number. If so, it returns true. If not, it returns false. For example:
<?php is_numeric( 'abcd123' ) or die('提供的参数不是数字');
Second: Use regular expression matching. If the match is successful, it is a number, and true is returned. If the match is unsuccessful, it is not a number, and false is returned.
For example:
<?php preg_match('/^\d+$/i', 'abcd123') or die('提供的数据不是数字');
Recommendation: "PHP Tutorial"
The above is the detailed content of How to judge whether php is a number. For more information, please follow other related articles on the PHP Chinese website!