note 29067 rejected from function.is-int by maxim
| From: | maxim@php.net | Date: | Sat, 01 Feb 2003 02:40:44 +0000 |
| Subject: | note 29067 rejected from function.is-int by maxim | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-43243@lists.php.net to get a copy of this message | ||
This function returns true for cases '+123', '-0053' and '2'.
There must be at least one digit in the string $str and there can be a sign.
function str_is_int($str) {
return preg_match('/^[+-]?\d+$/', $str);
}
The second function ignores white spaces at the beginning and at the end of $str. It returns true
for the same cases as the function above and also for cases as ' 351', '13 '
and ' 235 '.
function str_is_int($str) {
return preg_match('/^[+-]?\d+$/', trim($str));
}