3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function fdate($date) { $count = 0; if (strpos($date, "-") === false) { $date = preg_replace("~.*?(\d+)/(\d+)/(\d+)(\s+(\d+:\d+(:\d+)?))?.*~", "$3-$2-$1 $5", $date, 1, $count); if (!$count) { $date = false; } } if ($date && preg_match("~\d{4}-\d{1,2}-\d{1,2}( \d{2}:\d{2}:\d{2})?~", $date)) { return $date; } else { return "false"; } } echo fdate("2015-04-09"), "\r\n"; echo fdate("09-04-2015"), "\r\n"; echo "\r\n"; echo fdate("2015/04/09"), "\r\n"; echo fdate("09/04/2015"), "\r\n";
based on 2IfZ2
Output for 5.3.18 - 7.2.0
2015-04-09 false false 2015-04-09