Created
July 9, 2018 00:53
-
-
Save mdrakibhossainhawlader/087c2a569ffc60e72497f653c1f97066 to your computer and use it in GitHub Desktop.
PHP: Timestamp validator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Checks if a string is a valid timestamp. | |
| * | |
| * @param string $timestamp Timestamp to validate. | |
| * | |
| * @return bool | |
| */ | |
| function is_timestamp($timestamp) | |
| { | |
| $check = (is_int($timestamp) OR is_float($timestamp)) | |
| ? $timestamp | |
| : (string) (int) $timestamp; | |
| return ($check === $timestamp) | |
| AND ( (int) $timestamp <= PHP_INT_MAX) | |
| AND ( (int) $timestamp >= ~PHP_INT_MAX); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment