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]); var_dump($dateParts); $dateTime = new \DateTime(); //$dateTime->setDate(implode('-', $dateParts)); //$dateTime->setTime(implode(':', $timeParts)); return $dateTime; } var_dump(getDateFromFilename($filenameNew));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SPjfn
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'
   39     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/SPjfn
function name:  getDateFromFilename
number of ops:  37
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                                               'ltrim'
          4        SEND_VAR                                                 !0
          5        SEND_VAL                                                 'PX'
          6        DO_ICALL                                         $10     
          7        ASSIGN                                                   !0, $10
   23     8        INIT_FCALL                                               'explode'
          9        SEND_VAL                                                 '_'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $12     
         12        FETCH_LIST_R                                     $13     $12, 0
         13        ASSIGN                                                   !3, $13
         14        FETCH_LIST_R                                     $15     $12, 1
         15        ASSIGN                                                   !4, $15
         16        FREE                                                     $12
   25    17        INIT_FCALL                                               'preg_match'
         18        SEND_VAR                                                 !1
         19        SEND_VAR                                                 !3
         20        SEND_REF                                                 !5
         21        DO_ICALL                                                 
   26    22        UNSET_DIM                                                !5, 0
   28    23        INIT_FCALL                                               'preg_match'
         24        SEND_VAR                                                 !2
         25        SEND_VAR                                                 !4
         26        SEND_REF                                                 !6
         27        DO_ICALL                                                 
   29    28        UNSET_DIM                                                !6, 0
   31    29        INIT_FCALL                                               'var_dump'
         30        SEND_VAR                                                 !5
         31        DO_ICALL                                                 
   32    32        NEW                                              $20     'DateTime'
         33        DO_FCALL                                      0          
         34        ASSIGN                                                   !7, $20
   36    35      > RETURN                                                   !7
   37    36*     > RETURN                                                   null

End of function getdatefromfilename

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.25 ms | 1402 KiB | 22 Q