60, 'H' => 3600, 'D' => 86400, 'W' => 604800 ]; /** * @param $val * @return float|int * @throws Exception if can't parse $val to seconds */ public static function convertToSeconds( $val ) { if (preg_match('/^\d+$/', $val)) { return (int)$val; } preg_match('/(\d+)([MHDW])/i', $val, $matches); if (!$matches) { throw new Exception('Wrong TTL Syntax for: '.$val); } $secondsPerSingeUnit = static::$units[strtoupper($matches[2])]; $amount = (int)$matches[1]; return $secondsPerSingeUnit * $amount; } }