3v4l.org

run code in 300+ PHP versions simultaneously
<?php function find_date( $string ) { //Define month name: $month_names = array( "january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december" ); $month_name_shorts = array( "jan" ); $month_number=$month=$matches_year=$year=$matches_month_number=$matches_month_word=$matches_day_number=""; //Match dates: 01/01/2012 or 30-12-11 or 1 2 1985 preg_match( '/([0-9]?[0-9])[\.\-\/ ]?([0-1]?[0-9])[\.\-\/ ]?([0-9]{2,4})/', $string, $matches ); if ( $matches ) { if ( $matches[1] ) $day = $matches[1]; if ( $matches[2] ) $month = $matches[2]; if ( $matches[3] ) $year = $matches[3]; } //Match month name: preg_match( '/(' . implode( '|', $month_names ) . ')/i', $string, $matches_month_word ); if ( $matches_month_word ) { echo strtolower( $matches_month_word[1]);exit; if ( $matches_month_word[1] ) $month = array_search( strtolower( $matches_month_word[1] ), $month_names ) + 1; } //Match 5th 1st day: preg_match( '/([0-9]?[0-9])(st|nd|th)/', $string, $matches_day ); if ( $matches_day ) { if ( $matches_day[1] ) $day = $matches_day[1]; } //Match Year if not already setted: if ( empty( $year ) ) { preg_match( '/[0-9]{2}/', $string, $matches_year ); if ( $matches_year[0] ) $year = $matches_year[0]; } if ( ! empty ( $day ) && ! empty ( $month ) && empty( $year ) ) { preg_match( '/[0-9]{2}/', $string, $matches_year ); if ( $matches_year[0] ) $year = $matches_year[0]; } $day = '01'; //Leading 0 if ( 1 == strlen( $day ) ) $day = '0' . $day; //Leading 0 if ( 1 == strlen( $month ) ) $month = '0' . $month; //Check year: if ( 2 == strlen( $year ) && $year > 20 ) $year = '19' . $year; else if ( 2 == strlen( $year ) && $year < 20 ) $year = '20' . $year; $date = array( 'year' => $year, 'month' => $month, 'day' => $day ); //Return false if nothing found: if ( empty( $year ) && empty( $month ) && empty( $day ) ) return false; else return date('Y-m-d',strtotime($date['year'].'-'.$date['month'].'-01')); } echo find_date('Fund Factsheet Syariah - Jan 1914');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CNOiX
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   87     0  E >   INIT_FCALL                                               'find_date'
          1        SEND_VAL                                                 'Fund+Factsheet+Syariah+-+Jan+1914'
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
          4      > RETURN                                                   1

Function find_date:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 28
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 24
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 28
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 58
Branch analysis from position: 40
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 58
2 jumps found. (Code = 43) Position 1 = 64, Position 2 = 68
Branch analysis from position: 64
2 jumps found. (Code = 43) Position 1 = 66, Position 2 = 68
Branch analysis from position: 66
2 jumps found. (Code = 43) Position 1 = 70, Position 2 = 79
Branch analysis from position: 70
2 jumps found. (Code = 43) Position 1 = 77, Position 2 = 79
Branch analysis from position: 77
2 jumps found. (Code = 46) Position 1 = 82, Position 2 = 85
Branch analysis from position: 82
2 jumps found. (Code = 46) Position 1 = 86, Position 2 = 88
Branch analysis from position: 86
2 jumps found. (Code = 43) Position 1 = 89, Position 2 = 98
Branch analysis from position: 89
2 jumps found. (Code = 43) Position 1 = 96, Position 2 = 98
Branch analysis from position: 96
2 jumps found. (Code = 43) Position 1 = 102, Position 2 = 104
Branch analysis from position: 102
2 jumps found. (Code = 43) Position 1 = 107, Position 2 = 109
Branch analysis from position: 107
2 jumps found. (Code = 46) Position 1 = 112, Position 2 = 114
Branch analysis from position: 112
2 jumps found. (Code = 43) Position 1 = 115, Position 2 = 118
Branch analysis from position: 115
1 jumps found. (Code = 42) Position 1 = 126
Branch analysis from position: 126
2 jumps found. (Code = 46) Position 1 = 132, Position 2 = 134
Branch analysis from position: 132
2 jumps found. (Code = 46) Position 1 = 135, Position 2 = 137
Branch analysis from position: 135
2 jumps found. (Code = 43) Position 1 = 138, Position 2 = 140
Branch analysis from position: 138
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 140
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 137
Branch analysis from position: 134
Branch analysis from position: 118
2 jumps found. (Code = 46) Position 1 = 121, Position 2 = 123
Branch analysis from position: 121
2 jumps found. (Code = 43) Position 1 = 124, Position 2 = 126
Branch analysis from position: 124
2 jumps found. (Code = 46) Position 1 = 132, Position 2 = 134
Branch analysis from position: 132
Branch analysis from position: 134
Branch analysis from position: 126
Branch analysis from position: 123
Branch analysis from position: 114
Branch analysis from position: 109
Branch analysis from position: 104
Branch analysis from position: 98
Branch analysis from position: 98
Branch analysis from position: 88
Branch analysis from position: 85
Branch analysis from position: 79
Branch analysis from position: 79
Branch analysis from position: 68
Branch analysis from position: 68
Branch analysis from position: 28
Branch analysis from position: 24
Branch analysis from position: 20
Branch analysis from position: 28
filename:       /in/CNOiX
function name:  find_date
number of ops:  154
compiled vars:  !0 = $string, !1 = $month_names, !2 = $month_name_shorts, !3 = $month_number, !4 = $month, !5 = $matches_year, !6 = $year, !7 = $matches_month_number, !8 = $matches_month_word, !9 = $matches_day_number, !10 = $matches, !11 = $day, !12 = $matches_day, !13 = $date
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, <array>
   19     2        ASSIGN                                                   !2, <array>
   22     3        ASSIGN                                           ~16     !9, ''
          4        ASSIGN                                           ~17     !8, ~16
          5        ASSIGN                                           ~18     !7, ~17
          6        ASSIGN                                           ~19     !6, ~18
          7        ASSIGN                                           ~20     !5, ~19
          8        ASSIGN                                           ~21     !4, ~20
          9        ASSIGN                                                   !3, ~21
   25    10        INIT_FCALL                                               'preg_match'
         11        SEND_VAL                                                 '%2F%28%5B0-9%5D%3F%5B0-9%5D%29%5B%5C.%5C-%5C%2F+%5D%3F%28%5B0-1%5D%3F%5B0-9%5D%29%5B%5C.%5C-%5C%2F+%5D%3F%28%5B0-9%5D%7B2%2C4%7D%29%2F'
         12        SEND_VAR                                                 !0
         13        SEND_REF                                                 !10
         14        DO_ICALL                                                 
   26    15      > JMPZ                                                     !10, ->28
   27    16    >   FETCH_DIM_R                                      ~24     !10, 1
         17      > JMPZ                                                     ~24, ->20
   28    18    >   FETCH_DIM_R                                      ~25     !10, 1
         19        ASSIGN                                                   !11, ~25
   29    20    >   FETCH_DIM_R                                      ~27     !10, 2
         21      > JMPZ                                                     ~27, ->24
   30    22    >   FETCH_DIM_R                                      ~28     !10, 2
         23        ASSIGN                                                   !4, ~28
   31    24    >   FETCH_DIM_R                                      ~30     !10, 3
         25      > JMPZ                                                     ~30, ->28
   32    26    >   FETCH_DIM_R                                      ~31     !10, 3
         27        ASSIGN                                                   !6, ~31
   35    28    >   INIT_FCALL                                               'preg_match'
         29        INIT_FCALL                                               'implode'
         30        SEND_VAL                                                 '%7C'
         31        SEND_VAR                                                 !1
         32        DO_ICALL                                         $33     
         33        CONCAT                                           ~34     '%2F%28', $33
         34        CONCAT                                           ~35     ~34, '%29%2Fi'
         35        SEND_VAL                                                 ~35
         36        SEND_VAR                                                 !0
         37        SEND_REF                                                 !8
         38        DO_ICALL                                                 
   37    39      > JMPZ                                                     !8, ->58
   38    40    >   INIT_FCALL                                               'strtolower'
         41        FETCH_DIM_R                                      ~37     !8, 1
         42        SEND_VAL                                                 ~37
         43        DO_ICALL                                         $38     
         44        ECHO                                                     $38
         45      > EXIT                                                     
   39    46*       FETCH_DIM_R                                      ~39     !8, 1
         47*       JMPZ                                                     ~39, ->58
   40    48*       INIT_FCALL                                               'array_search'
         49*       INIT_FCALL                                               'strtolower'
         50*       FETCH_DIM_R                                      ~40     !8, 1
         51*       SEND_VAL                                                 ~40
         52*       DO_ICALL                                         $41     
         53*       SEND_VAR                                                 $41
         54*       SEND_VAR                                                 !1
         55*       DO_ICALL                                         $42     
         56*       ADD                                              ~43     $42, 1
         57*       ASSIGN                                                   !4, ~43
   46    58    >   INIT_FCALL                                               'preg_match'
         59        SEND_VAL                                                 '%2F%28%5B0-9%5D%3F%5B0-9%5D%29%28st%7Cnd%7Cth%29%2F'
         60        SEND_VAR                                                 !0
         61        SEND_REF                                                 !12
         62        DO_ICALL                                                 
   47    63      > JMPZ                                                     !12, ->68
   48    64    >   FETCH_DIM_R                                      ~46     !12, 1
         65      > JMPZ                                                     ~46, ->68
   49    66    >   FETCH_DIM_R                                      ~47     !12, 1
         67        ASSIGN                                                   !11, ~47
   52    68    >   ISSET_ISEMPTY_CV                                         !6
         69      > JMPZ                                                     ~49, ->79
   53    70    >   INIT_FCALL                                               'preg_match'
         71        SEND_VAL                                                 '%2F%5B0-9%5D%7B2%7D%2F'
         72        SEND_VAR                                                 !0
         73        SEND_REF                                                 !5
         74        DO_ICALL                                                 
   54    75        FETCH_DIM_R                                      ~51     !5, 0
         76      > JMPZ                                                     ~51, ->79
   55    77    >   FETCH_DIM_R                                      ~52     !5, 0
         78        ASSIGN                                                   !6, ~52
   57    79    >   ISSET_ISEMPTY_CV                                 ~54     !11
         80        BOOL_NOT                                         ~55     ~54
         81      > JMPZ_EX                                          ~55     ~55, ->85
         82    >   ISSET_ISEMPTY_CV                                 ~56     !4
         83        BOOL_NOT                                         ~57     ~56
         84        BOOL                                             ~55     ~57
         85    > > JMPZ_EX                                          ~55     ~55, ->88
         86    >   ISSET_ISEMPTY_CV                                 ~58     !6
         87        BOOL                                             ~55     ~58
         88    > > JMPZ                                                     ~55, ->98
   58    89    >   INIT_FCALL                                               'preg_match'
         90        SEND_VAL                                                 '%2F%5B0-9%5D%7B2%7D%2F'
         91        SEND_VAR                                                 !0
         92        SEND_REF                                                 !5
         93        DO_ICALL                                                 
   59    94        FETCH_DIM_R                                      ~60     !5, 0
         95      > JMPZ                                                     ~60, ->98
   60    96    >   FETCH_DIM_R                                      ~61     !5, 0
         97        ASSIGN                                                   !6, ~61
   62    98    >   ASSIGN                                                   !11, '01'
   64    99        STRLEN                                           ~64     !11
        100        IS_EQUAL                                                 ~64, 1
        101      > JMPZ                                                     ~65, ->104
   65   102    >   CONCAT                                           ~66     '0', !11
        103        ASSIGN                                                   !11, ~66
   67   104    >   STRLEN                                           ~68     !4
        105        IS_EQUAL                                                 ~68, 1
        106      > JMPZ                                                     ~69, ->109
   68   107    >   CONCAT                                           ~70     '0', !4
        108        ASSIGN                                                   !4, ~70
   70   109    >   STRLEN                                           ~72     !6
        110        IS_EQUAL                                         ~73     ~72, 2
        111      > JMPZ_EX                                          ~73     ~73, ->114
        112    >   IS_SMALLER                                       ~74     20, !6
        113        BOOL                                             ~73     ~74
        114    > > JMPZ                                                     ~73, ->118
   71   115    >   CONCAT                                           ~75     '19', !6
        116        ASSIGN                                                   !6, ~75
        117      > JMP                                                      ->126
   72   118    >   STRLEN                                           ~77     !6
        119        IS_EQUAL                                         ~78     ~77, 2
        120      > JMPZ_EX                                          ~78     ~78, ->123
        121    >   IS_SMALLER                                       ~79     !6, 20
        122        BOOL                                             ~78     ~79
        123    > > JMPZ                                                     ~78, ->126
   73   124    >   CONCAT                                           ~80     '20', !6
        125        ASSIGN                                                   !6, ~80
   75   126    >   INIT_ARRAY                                       ~82     !6, 'year'
   76   127        ADD_ARRAY_ELEMENT                                ~82     !4, 'month'
   77   128        ADD_ARRAY_ELEMENT                                ~82     !11, 'day'
   74   129        ASSIGN                                                   !13, ~82
   80   130        ISSET_ISEMPTY_CV                                 ~84     !6
        131      > JMPZ_EX                                          ~84     ~84, ->134
        132    >   ISSET_ISEMPTY_CV                                 ~85     !4
        133        BOOL                                             ~84     ~85
        134    > > JMPZ_EX                                          ~84     ~84, ->137
        135    >   ISSET_ISEMPTY_CV                                 ~86     !11
        136        BOOL                                             ~84     ~86
        137    > > JMPZ                                                     ~84, ->140
   81   138    > > RETURN                                                   <false>
        139*       JMP                                                      ->153
   83   140    >   INIT_FCALL                                               'date'
        141        SEND_VAL                                                 'Y-m-d'
        142        INIT_FCALL                                               'strtotime'
        143        FETCH_DIM_R                                      ~87     !13, 'year'
        144        CONCAT                                           ~88     ~87, '-'
        145        FETCH_DIM_R                                      ~89     !13, 'month'
        146        CONCAT                                           ~90     ~88, ~89
        147        CONCAT                                           ~91     ~90, '-01'
        148        SEND_VAL                                                 ~91
        149        DO_ICALL                                         $92     
        150        SEND_VAR                                                 $92
        151        DO_ICALL                                         $93     
        152      > RETURN                                                   $93
   84   153*     > RETURN                                                   null

End of function find_date

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.55 ms | 1415 KiB | 26 Q