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]); return sprintf("%s %s", implode('-', $dateParts), implode('-', $timePrts)); } var_dump(getDateFromFilename($filenameNew));
Output for 8.1.24 - 8.1.28, 8.2.11 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Warning: Undefined variable $timePrts in /in/2EPIt on line 31 Fatal error: Uncaught TypeError: implode(): Argument #1 ($array) must be of type array, string given in /in/2EPIt:31 Stack trace: #0 /in/2EPIt(31): implode('-', NULL) #1 /in/2EPIt(34): getDateFromFilename('20170713_103320...') #2 {main} thrown in /in/2EPIt on line 31
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Warning: Undefined variable $timePrts in /in/2EPIt on line 31 Fatal error: Uncaught TypeError: implode(): Argument #1 ($array) must be of type array, string given in /in/2EPIt:31 Stack trace: #0 /in/2EPIt(31): implode('-', NULL) #1 /in/2EPIt(34): getDateFromFilename('20170713_103320...') #2 {main} thrown in /in/2EPIt on line 31
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.23, 8.2.0 - 8.2.10
Warning: Undefined variable $timePrts in /in/2EPIt on line 31 Fatal error: Uncaught TypeError: implode(): Argument #1 ($pieces) must be of type array, string given in /in/2EPIt:31 Stack trace: #0 /in/2EPIt(31): implode('-', NULL) #1 /in/2EPIt(34): getDateFromFilename('20170713_103320...') #2 {main} thrown in /in/2EPIt on line 31
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Notice: Undefined variable: timePrts in /in/2EPIt on line 31 Warning: implode(): Invalid arguments passed in /in/2EPIt on line 31 string(11) "2017-07-13 "
Output for 7.3.32 - 7.3.33
Warning: implode(): Invalid arguments passed in /in/2EPIt on line 31 string(11) "2017-07-13 "

preferences:
162.26 ms | 401 KiB | 188 Q