3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function scholar_parse_time($time) // {{{ { '/^\s*(?P<hour>\d+)(?>:(?P<minute>\d+))?(?>:(?P<second>\d+(\.\d*)?))?\s*$/'; if (preg_match('/^\s*(?>(?P<hour>\d+)(?>:(?P<minute>\d+)(?>:(?P<second>\d+)(?P<millis>\.\d*)?)?)?)\s*$/', $time, $match)) { $h = intval($match['hour']); $m = isset($match['minute']) ? intval($match['minute']) : null; $s = isset($match['second']) ? intval($match['second']) : null; $ms = isset($match['millis']) ? round(floatval($match['millis']) * 1000) : null; if ($h < 24 && (null === $m || $m < 60) && (null === $s || $s < 60)) { return array( 'hour' => $h, 'minute' => $m, 'second' => $s, 'millis' => $ms, 'iso' => null === $m ? sprintf('%02d', $h) : (null === $s ? sprintf('%02d:%02d', $h, $m) : sprintf('%02d:%02d:%02d', $h, $m, $s) ), ); } } return false; } // }}} var_dump(scholar_parse_time('19')); var_dump(scholar_parse_date('19:01')); var_dump(scholar_parse_date('19:01:04')); var_dump(scholar_parse_date('19:01:32.')); var_dump(scholar_parse_date('19:01:32.3')); var_dump(scholar_parse_date('19:01.1'));
Output for 7.0.0 - 7.1.0
array(5) { ["hour"]=> int(19) ["minute"]=> NULL ["second"]=> NULL ["millis"]=> NULL ["iso"]=> string(2) "19" } Fatal error: Uncaught Error: Call to undefined function scholar_parse_date() in /in/4GWnC:32 Stack trace: #0 {main} thrown in /in/4GWnC on line 32
Process exited with code 255.
Output for 5.0.0 - 5.6.28, hhvm-3.10.0 - 3.12.0
array(5) { ["hour"]=> int(19) ["minute"]=> NULL ["second"]=> NULL ["millis"]=> NULL ["iso"]=> string(2) "19" } Fatal error: Call to undefined function scholar_parse_date() in /in/4GWnC on line 32
Process exited with code 255.
Output for 4.4.5 - 4.4.9
array(5) { ["hour"]=> int(19) ["minute"]=> NULL ["second"]=> NULL ["millis"]=> NULL ["iso"]=> string(2) "19" } Fatal error: Call to undefined function: scholar_parse_date() in /in/4GWnC on line 32
Process exited with code 255.
Output for 4.3.3 - 4.4.4
array(5) { ["hour"]=> int(19) ["minute"]=> NULL ["second"]=> NULL ["millis"]=> NULL ["iso"]=> string(2) "19" } Fatal error: Call to undefined function: scholar_parse_date() in /in/4GWnC on line 32
Process exited with code 255.
Output for 4.3.2
Notice: Undefined index: hour in /in/4GWnC on line 7 array(5) { ["hour"]=> int(0) ["minute"]=> NULL ["second"]=> NULL ["millis"]=> NULL ["iso"]=> string(2) "00" } Fatal error: Call to undefined function: scholar_parse_date() in /in/4GWnC on line 32
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Notice: Undefined index: hour in /in/4GWnC on line 7 array(5) { ["hour"]=> int(0) ["minute"]=> NULL ["second"]=> NULL ["millis"]=> NULL ["iso"]=> string(2) "00" } Fatal error: Call to undefined function: scholar_parse_date() in /in/4GWnC on line 32