note 69916 added to function.ctype-digit

From: Date: Tue, 26 Sep 2006 13:31:33 +0000
Subject: note 69916 added to function.ctype-digit
Groups: php.notes 
Request: Send a blank email to php-notes+get-117681@lists.php.net to get a copy of this message
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 ---- Server IP: 217.160.72.57 Probable Submitter: 87.234.91.41 ---- Manual Page -- http://www.php.net/manual/en/function.ctype-digit.php Edit -- https://master.php.net/note/edit/69916 Del: integrated -- https://master.php.net/note/delete/69916/integrated Del: useless -- https://master.php.net/note/delete/69916/useless Del: bad code -- https://master.php.net/note/delete/69916/bad+code Del: spam -- https://master.php.net/note/delete/69916/spam Del: non-english -- https://master.php.net/note/delete/69916/non-english Del: in docs -- https://master.php.net/note/delete/69916/in+docs Del: other reasons-- https://master.php.net/note/delete/69916 Reject -- https://master.php.net/note/reject/69916 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#117681) next »