note 69916 deleted from function.ctype-digit by nlopess
| From: | nlopess@php.net | Date: | Tue, 26 Sep 2006 16:33:36 +0000 |
| Subject: | note 69916 deleted from function.ctype-digit by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-117690@lists.php.net to get a copy of this message | ||
Note Submitter: info at mopox.de
----
ctype_digit also returns true if the string is empty. if you need to rule that out, better use
preg_match. but preg_metch also is true for the int. you better check the data type befor, if you
care for that.
<?
// ctype test
$val1 = '';
$val2 = '234';
$val3 = 234;
$val4 = '234e';
ctype_digit($val1) && print "ctype val1 is true<br>";
ctype_digit($val2) && print "ctype val2 is true<br>";
ctype_digit($val3) && print "ctype val3 is true<br>";
ctype_digit($val4) && print "ctype val4 is true<br>";
preg_match('/^\d+$/', $val1) && print "preg_match val1 is
true<br>";
preg_match('/^\d+$/', $val2) && print "preg_match val2 is
true<br>";
preg_match('/^\d+$/', $val3) && print "preg_match val3 is
true<br>";
preg_match('/^\d+$/', $val4) && print "preg_match val4 is
true<br>";
?>
returns:
ctype val1 is true
ctype val2 is true
preg_match val2 is true
preg_match val3 is true