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})/'; 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($dateParts[1], $dateParts[2], $dateParts[3]); $dateTime->setTime($timeParts[1], $timeParts[2], $timeParts[3]); return $dateTime; } var_dump(getDateFromFilename($filenameNew));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FoCip
function name:  (null)
number of ops:  9
compiled vars:  !0 = $filenameNew, !1 = $filenameOld
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'PX20170713_103320_2651093_00001'
    4     1        ASSIGN                                                   !1, '5956e5781e4f1-20170630_233347_5712837_00001.xml'
   37     2        INIT_FCALL                                               'var_dump'
          3        INIT_FCALL                                               'getdatefromfilename'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $4      
          6        SEND_VAR                                                 $4
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function getdatefromfilename:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FoCip
function name:  getDateFromFilename
number of ops:  51
compiled vars:  !0 = $filename, !1 = $dateRegexp, !2 = $timeRegexp, !3 = $date, !4 = $time, !5 = $dateParts, !6 = $timeParts, !7 = $dateTime
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   19     1        ASSIGN                                                   !1, '%2F%28%5B0-9%5D%7B4%7D%29%28%5B0-9%5D%7B2%7D%29%28%5B0-9%5D%7B2%7D%29%2F'
   20     2        ASSIGN                                                   !2, '%2F%28%5B0-9%5D%7B2%7D%29%28%5B0-9%5D%7B2%7D%29%28%5B0-9%5D%7B2%7D%29%2F'
   22     3        INIT_FCALL                                               'explode'
          4        SEND_VAL                                                 '_'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $10     
          7        FETCH_LIST_R                                     $11     $10, 0
          8        ASSIGN                                                   !3, $11
          9        FETCH_LIST_R                                     $13     $10, 1
         10        ASSIGN                                                   !4, $13
         11        FREE                                                     $10
   24    12        INIT_FCALL                                               'preg_match'
         13        SEND_VAR                                                 !1
         14        SEND_VAR                                                 !3
         15        SEND_REF                                                 !5
         16        DO_ICALL                                                 
   25    17        UNSET_DIM                                                !5, 0
   27    18        INIT_FCALL                                               'preg_match'
         19        SEND_VAR                                                 !2
         20        SEND_VAR                                                 !4
         21        SEND_REF                                                 !6
         22        DO_ICALL                                                 
   28    23        UNSET_DIM                                                !6, 0
   30    24        NEW                                              $17     'DateTime'
         25        DO_FCALL                                      0          
         26        ASSIGN                                                   !7, $17
   31    27        INIT_METHOD_CALL                                         !7, 'setDate'
         28        CHECK_FUNC_ARG                                           
         29        FETCH_DIM_FUNC_ARG                               $20     !5, 1
         30        SEND_FUNC_ARG                                            $20
         31        CHECK_FUNC_ARG                                           
         32        FETCH_DIM_FUNC_ARG                               $21     !5, 2
         33        SEND_FUNC_ARG                                            $21
         34        CHECK_FUNC_ARG                                           
         35        FETCH_DIM_FUNC_ARG                               $22     !5, 3
         36        SEND_FUNC_ARG                                            $22
         37        DO_FCALL                                      0          
   32    38        INIT_METHOD_CALL                                         !7, 'setTime'
         39        CHECK_FUNC_ARG                                           
         40        FETCH_DIM_FUNC_ARG                               $24     !6, 1
         41        SEND_FUNC_ARG                                            $24
         42        CHECK_FUNC_ARG                                           
         43        FETCH_DIM_FUNC_ARG                               $25     !6, 2
         44        SEND_FUNC_ARG                                            $25
         45        CHECK_FUNC_ARG                                           
         46        FETCH_DIM_FUNC_ARG                               $26     !6, 3
         47        SEND_FUNC_ARG                                            $26
         48        DO_FCALL                                      0          
   34    49      > RETURN                                                   !7
   35    50*     > RETURN                                                   null

End of function getdatefromfilename

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.9 ms | 1403 KiB | 20 Q