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

End of function find_date

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
183.95 ms | 1411 KiB | 26 Q