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 * * If this fails it will throw an appropriate exception to * be handled gracefully. */ function getDateFromFilename(string $filename) { $dateRegexp = '/([0-9]{4})([0-9]{2})([0-9]{2})/'; $timeRegexp = '/([0-9]{2})([0-9]{2})([0-9]{2})/'; $filename = ltrim($filename, 'PX'); list($date, $time) = explode('_', $filename); preg_match_all($dateRegexp, $date, $dateParts, PREG_SET_ORDER, 0); return implode('-', $dateParts); } var_dump(getDateFromFilename($filenameNew));
based on s7Mul
Output for hhvm-3.15.4, 7.0.0 - 7.2.6
Notice: Array to string conversion in /in/QseJs on line 26 string(5) "Array"
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/QseJs on line 29 and defined in /in/QseJs on line 17
Process exited with code 255.