note 29067 added to function.is-int

From: Date: Fri, 31 Jan 2003 21:26:51 +0000
Subject: note 29067 added to function.is-int
Groups: php.notes 
Request: Send a blank email to php-notes+get-43229@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)); } -- http://www.php.net/manual/en/function.is-int.php http://master.php.net/manage/user-notes.php?action=edit+29067 http://master.php.net/manage/user-notes.php?action=delete+29067 http://master.php.net/manage/user-notes.php?action=reject+29067

« previous php.notes (#43229) next »