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

End of function find_date

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.87 ms | 1411 KiB | 26 Q