3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $filenameNew = 'PX20170713_103320_2651093_00001'; $filenameOld = '5956e5781e4f1-20170630_233347_5712837_00001.xml'; //$timeslug = implode(array_slice(explode('_', rtrim(basename($fileToProcess), ".xml" )), 0, 2)); //$datetime = date('c', strtotime($timeslug)); /** * Get a date time object from an AX filename. * * Example filename: PX20170713_103320_2651093_00001.xml */ function getDateFromFilename(string $filename) { $filename = ltrim($filename, 'PX'); list($date, $time) = explode('_', $filename); return [$date, $time]; } var_dump(getDateFromFilename($filenameNew));
based on ohWEF
Output for hhvm-3.15.4, 7.0.0 - 7.2.6
array(2) { [0]=> string(8) "20170713" [1]=> string(6) "103320" }
Output for 5.6.0 - 5.6.30
Catchable fatal error: Argument 1 passed to getDateFromFilename() must be an instance of string, string given, called in /in/s7Mul on line 22 and defined in /in/s7Mul on line 14
Process exited with code 255.