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_all($dateRegexp, $date, $dateParts, PREG_SET_ORDER, 0); return implode('-', $dateParts); } var_dump(getDateFromFilename($filenameNew));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QseJs
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'
   29     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/QseJs
function name:  getDateFromFilename
number of ops:  30
compiled vars:  !0 = $filename, !1 = $dateRegexp, !2 = $timeRegexp, !3 = $date, !4 = $time, !5 = $dateParts
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'
   21     3        INIT_FCALL                                               'ltrim'
          4        SEND_VAR                                                 !0
          5        SEND_VAL                                                 'PX'
          6        DO_ICALL                                         $8      
          7        ASSIGN                                                   !0, $8
   22     8        INIT_FCALL                                               'explode'
          9        SEND_VAL                                                 '_'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $10     
         12        FETCH_LIST_R                                     $11     $10, 0
         13        ASSIGN                                                   !3, $11
         14        FETCH_LIST_R                                     $13     $10, 1
         15        ASSIGN                                                   !4, $13
         16        FREE                                                     $10
   24    17        INIT_FCALL                                               'preg_match_all'
         18        SEND_VAR                                                 !1
         19        SEND_VAR                                                 !3
         20        SEND_REF                                                 !5
         21        SEND_VAL                                                 2
         22        SEND_VAL                                                 0
         23        DO_ICALL                                                 
   26    24        INIT_FCALL                                               'implode'
         25        SEND_VAL                                                 '-'
         26        SEND_VAR                                                 !5
         27        DO_ICALL                                         $16     
         28      > RETURN                                                   $16
   27    29*     > RETURN                                                   null

End of function getdatefromfilename

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.45 ms | 1403 KiB | 24 Q