3v4l.org

run code in 300+ PHP versions simultaneously
<?php function scholar_parse_date($date) { if (preg_match('/^\s*(?P<year>\d+)(?>-(?P<month>\d{1,2}))?(?>-(?P<day>\d{1,2}))?\s*$/', $date, $match)) { $y = intval($match['year']); $m = isset($match['month']) ? intval($match['month']) : null; $d = isset($match['day']) ? intval($match['day']) : null; // Jezeli $m jest nullem, tzn. ze $d tez jest nullem, wiec // rok jako liczba calkowita jest poprawny. // Jezeli $m nie jest nullem, musi byc z przedzialu 1..12. // Jezeli $d jest nullem, nic wiecej nie trzeba sprawdzac, // jezeli nie jest, trzeba sprawdzic pelna date. $valid = ((null === $m) || (1 <= $m && $m <= 12)) && ((null === $d) || checkdate($m, $d, $y)); if ($valid) { return array( 'year' => $y, 'month' => $m, 'day' => $d, 'iso' => sprintf('%04d-%02d-%02d', $y, $m, $d), // ISO 8601 ); } } return false; } var_dump(scholar_parse_date('1992')); var_dump(scholar_parse_date('1992-01')); var_dump(scholar_parse_date('1992-01-04')); var_dump(scholar_parse_date('1992-01-32'));
Output for git.master, git.master_jit, rfc.property-hooks
array(4) { ["year"]=> int(1992) ["month"]=> NULL ["day"]=> NULL ["iso"]=> string(10) "1992-00-00" } array(4) { ["year"]=> int(1992) ["month"]=> int(1) ["day"]=> NULL ["iso"]=> string(10) "1992-01-00" } array(4) { ["year"]=> int(1992) ["month"]=> int(1) ["day"]=> int(4) ["iso"]=> string(10) "1992-01-04" } bool(false)

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
38.55 ms | 402 KiB | 8 Q