note 93560 added to function.is-int
| From: | me at rexxars dot com | Date: | Wed, 16 Sep 2009 12:23:02 +0000 |
| Subject: | note 93560 added to function.is-int | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-160613@lists.php.net to get a copy of this message | ||
I was looking for the fastest way to check for an unsigned integer which supported large numbers
like 4318943448871348 or 0xFFFFFFFF.
Fastest I came up with is this:
<?php
function is_unsigned_int($val) {
return ctype_digit((string) $value));
}
?>
Will return true on 1515, 0xFFFFFFFF, '3515' and '1365158185855141'.
Will return false on 0.1515, '415.4134' and '-616'.
Be aware though, before PHP 5.1.0 this will return true on an empty string.
According to my benchmarks this is about 30% faster than the regex ^\d+$.
----
Server IP: 69.147.83.197
Probable Submitter: 188.126.203.230
----
Manual Page -- http://www.php.net/manual/en/function.is-int.php
Edit -- https://master.php.net/note/edit/93560
Del: integrated -- https://master.php.net/note/delete/93560/integrated
Del: useless -- https://master.php.net/note/delete/93560/useless
Del: bad code -- https://master.php.net/note/delete/93560/bad+code
Del: spam -- https://master.php.net/note/delete/93560/spam
Del: non-english -- https://master.php.net/note/delete/93560/non-english
Del: in docs -- https://master.php.net/note/delete/93560/in+docs
Del: other reasons-- https://master.php.net/note/delete/93560
Reject -- https://master.php.net/note/reject/93560
Search -- https://master.php.net/manage/user-notes.php