Skip to content

Instantly share code, notes, and snippets.

@mdrakibhossainhawlader
Created July 9, 2018 00:53
Show Gist options
  • Save mdrakibhossainhawlader/087c2a569ffc60e72497f653c1f97066 to your computer and use it in GitHub Desktop.
Save mdrakibhossainhawlader/087c2a569ffc60e72497f653c1f97066 to your computer and use it in GitHub Desktop.
PHP: Timestamp validator
<?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