3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @param string $date format rrrr-mm-dd * @return mixed - false or date format d.m.rrrr which really exists */ function typicalFormat($date){ $date = explode('-', $date); if(count($date) == 3){ $year = $date[0]; $date[1] = preg_replace('~^0~', '', $date[1]); $date[0] = preg_replace('~^0~', '', $date[2]); $date[2] = $year; $date = implode('.', $date); if(existsDate($date, true) == 1){ return $date; } return false; } return false; } /** * @param string $date format d.m.rrrr * @return bool * @copyright Jakub Vrána, http://php.vrana.cz/ */ function existsDate($date, $millenium = true){ $millenium = ($millenium) ? '4' : '1,'; return preg_match('~^([1-9]|19|[12][0-8]|29(?=\\.([^2]|2\\.(([02468][048]|[13579][26])00|[0-9]{2}(0[48]|[2468][048]|[13579][26]))))|30(?=\\.[^2])|31(?=\\.([13578][02]?\\.)))\\.([1-9]|1[012])\\.[0-9]{'.$millenium.'}$~D', $date); } var_dump(typicalFormat('999-02-05')); die();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/qOpNO
function name:  (null)
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'typicalformat'
          2        SEND_VAL                                                 '999-02-05'
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
          6      > EXIT                                                     
          7*     > RETURN                                                   1

Function typicalformat:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 42
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 41
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qOpNO
function name:  typicalFormat
number of ops:  44
compiled vars:  !0 = $date, !1 = $year
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '-'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5        ASSIGN                                                   !0, $2
   11     6        COUNT                                            ~4      !0
          7        IS_EQUAL                                                 ~4, 3
          8      > JMPZ                                                     ~5, ->42
   12     9    >   FETCH_DIM_R                                      ~6      !0, 0
         10        ASSIGN                                                   !1, ~6
   13    11        INIT_FCALL                                               'preg_replace'
         12        SEND_VAL                                                 '%7E%5E0%7E'
         13        SEND_VAL                                                 ''
         14        FETCH_DIM_R                                      ~9      !0, 1
         15        SEND_VAL                                                 ~9
         16        DO_ICALL                                         $10     
         17        ASSIGN_DIM                                               !0, 1
         18        OP_DATA                                                  $10
   14    19        INIT_FCALL                                               'preg_replace'
         20        SEND_VAL                                                 '%7E%5E0%7E'
         21        SEND_VAL                                                 ''
         22        FETCH_DIM_R                                      ~12     !0, 2
         23        SEND_VAL                                                 ~12
         24        DO_ICALL                                         $13     
         25        ASSIGN_DIM                                               !0, 0
         26        OP_DATA                                                  $13
   15    27        ASSIGN_DIM                                               !0, 2
         28        OP_DATA                                                  !1
   16    29        INIT_FCALL                                               'implode'
         30        SEND_VAL                                                 '.'
         31        SEND_VAR                                                 !0
         32        DO_ICALL                                         $15     
         33        ASSIGN                                                   !0, $15
   17    34        INIT_FCALL_BY_NAME                                       'existsDate'
         35        SEND_VAR_EX                                              !0
         36        SEND_VAL_EX                                              <true>
         37        DO_FCALL                                      0  $17     
         38        IS_EQUAL                                                 $17, 1
         39      > JMPZ                                                     ~18, ->41
   18    40    > > RETURN                                                   !0
   20    41    > > RETURN                                                   <false>
   22    42    > > RETURN                                                   <false>
   23    43*     > RETURN                                                   null

End of function typicalformat

Function existsdate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qOpNO
function name:  existsDate
number of ops:  15
compiled vars:  !0 = $date, !1 = $millenium
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <true>
   31     2      > JMPZ                                                     !1, ->5
          3    >   QM_ASSIGN                                        ~2      '4'
          4      > JMP                                                      ->6
          5    >   QM_ASSIGN                                        ~2      '1%2C'
          6    >   ASSIGN                                                   !1, ~2
   32     7        INIT_FCALL                                               'preg_match'
          8        CONCAT                                           ~4      '%7E%5E%28%5B1-9%5D%7C19%7C%5B12%5D%5B0-8%5D%7C29%28%3F%3D%5C.%28%5B%5E2%5D%7C2%5C.%28%28%5B02468%5D%5B048%5D%7C%5B13579%5D%5B26%5D%2900%7C%5B0-9%5D%7B2%7D%280%5B48%5D%7C%5B2468%5D%5B048%5D%7C%5B13579%5D%5B26%5D%29%29%29%29%7C30%28%3F%3D%5C.%5B%5E2%5D%29%7C31%28%3F%3D%5C.%28%5B13578%5D%5B02%5D%3F%5C.%29%29%29%5C.%28%5B1-9%5D%7C1%5B012%5D%29%5C.%5B0-9%5D%7B', !1
          9        CONCAT                                           ~5      ~4, '%7D%24%7ED'
         10        SEND_VAL                                                 ~5
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $6      
         13      > RETURN                                                   $6
   33    14*     > RETURN                                                   null

End of function existsdate

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.48 ms | 1394 KiB | 24 Q