3v4l.org

run code in 300+ PHP versions simultaneously
<?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($dateRegexp, $date, $dateParts); unset($dateParts[0]); preg_match($timeRegexp, $time, $timeParts); unset($timeParts[0]); $dateTime = new \DateTime(); $dateTime->setDate(implode('-', $dateParts)); $dateTime->setTime(implode(':', $timeParts)); return $dateTime; } var_dump(getDateFromFilename($filenameNew));
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught ArgumentCountError: DateTime::setDate() expects exactly 3 arguments, 1 given in /in/g1LS6:32 Stack trace: #0 /in/g1LS6(32): DateTime->setDate('2017-07-13') #1 /in/g1LS6(38): getDateFromFilename('20170713_103320...') #2 {main} thrown in /in/g1LS6 on line 32
Process exited with code 255.

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:
33.36 ms | 401 KiB | 8 Q