3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $array = array("2017-06-30-18-21-52 foo.txt"); $array[] = "2017-07-01-19-06-21 bar bar.txt"; foreach ($array as $v) { $v = rtrim($v, ".txt"); $boom = explode(" ", $v); // Separate the date $date = DateTime::createFromFormat("Y-m-d-H-i-s", $boom[0]); unset($boom[0]); // Unset the date $text = implode(" ", $boom); echo $text." -- ".$date->format("F jS, Y")."\n"; }
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.2.0
foo -- June 30th, 2017 bar bar -- July 1st, 2017