3v4l.org

run code in 300+ PHP versions simultaneously
<?php function time_elapsed_string($datetime, $full = false) { $now = new DateTime; $ago = new DateTime($datetime); $diff = $now->diff($ago); $diff->w = floor($diff->d / 7); $diff->d -= $diff->w * 7; $string = array( 'h' => 'hour', 'i' => 'minute', 's' => 'second', ); foreach ($string as $k => &$v) { if ($diff->$k) { $v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : ''); } else { unset($string[$k]); } } if (!$full) $string = array_slice($string, 0, 1); return $string ? implode(', ', $string) . ' ago' : 'just now'; } $date = date_parse_from_format('Y-d-m H:i:s', '2014-02-05 5:22:35'); $unixTimestamp = mktime( $date['hour'], $date['minute'], $date['second'], $date['month'], $date['day'], $date['year'] ); echo time_elapsed_string($unixTimestamp, true);
Output for 8.3.0 - 8.3.6
Fatal error: Uncaught DateMalformedStringException: Failed to parse time string (1399000955) at position 8 (5): Unexpected character in /in/43iJB:5 Stack trace: #0 /in/43iJB(5): DateTime->__construct('1399000955') #1 /in/43iJB(34): time_elapsed_string(1399000955, true) #2 {main} thrown in /in/43iJB on line 5
Process exited with code 255.
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
Fatal error: Uncaught Exception: Failed to parse time string (1399000955) at position 8 (5): Unexpected character in /in/43iJB:5 Stack trace: #0 /in/43iJB(5): DateTime->__construct('1399000955') #1 /in/43iJB(34): time_elapsed_string(1399000955, true) #2 {main} thrown in /in/43iJB on line 5
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33, 8.0.0 - 8.0.12, 8.0.14 - 8.0.30
Fatal error: Uncaught Exception: DateTime::__construct(): Failed to parse time string (1399000955) at position 8 (5): Unexpected character in /in/43iJB:5 Stack trace: #0 /in/43iJB(5): DateTime->__construct('1399000955') #1 /in/43iJB(34): time_elapsed_string(1399000955, true) #2 {main} thrown in /in/43iJB on line 5
Process exited with code 255.
Output for 7.3.32 - 7.3.33, 8.0.13
Fatal error: Uncaught Exception: DateTime::__construct(): Failed to parse time string (1399008155) at position 7 (1): Unexpected character in /in/43iJB:5 Stack trace: #0 /in/43iJB(5): DateTime->__construct('1399008155') #1 /in/43iJB(34): time_elapsed_string(1399008155, true) #2 {main} thrown in /in/43iJB on line 5
Process exited with code 255.
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1399000955) at position 8 (5): Unexpected character' in /in/43iJB:5 Stack trace: #0 /in/43iJB(5): DateTime->__construct('1399000955') #1 /in/43iJB(34): time_elapsed_string(1399000955, true) #2 {main} thrown in /in/43iJB on line 5
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Fatal error: Call to undefined function date_parse_from_format() in /in/43iJB on line 28
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected '&', expecting T_VARIABLE or '$' in /in/43iJB on line 16
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected '&', expecting T_VARIABLE or '$' in /in/43iJB on line 16
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_VARIABLE' or `'$'' in /in/43iJB on line 16
Process exited with code 255.

preferences:
224.36 ms | 401 KiB | 330 Q