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+$.