3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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 ); echo ($matches_month_word[1]);exit; if ( $matches_month_word ) { 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');
based on TZcs1
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/3jDvi
function name:  (null)
number of ops:  6
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   3     0  E >   NOP                                                      
  83     1        INIT_FCALL                                               'find_date'
         2        SEND_VAL                                                 'Fund+Factsheet+Syariah+-+Jan+1914'
         3        DO_FCALL                                      0  $0      
         4        ECHO                                                     $0
         5      > RETURN                                                   1

Function find_date:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 15, Position 2 = 27
Branch analysis from position: 15
Jump found. Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
Jump found. Position 1 = 21, Position 2 = 23
Branch analysis from position: 21
Jump found. Position 1 = 25, Position 2 = 27
Branch analysis from position: 25
Jump found. Position 1 = -2
Branch analysis from position: 27
Branch analysis from position: 23
Branch analysis from position: 19
Branch analysis from position: 27
filename:       /in/3jDvi
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      
   6     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                                                 
  33    38        FETCH_DIM_R                                      $35     !7, 1
        39        ECHO                                                     $35
        40      > EXIT                                                     
  34    41*       JMPZ                                                     !7, ->54
  35    42*       FETCH_DIM_R                                      $36     !7, 1
        43*       JMPZ                                                     $36, ->54
  36    44*       INIT_FCALL                                               'array_search'
        45*       INIT_FCALL                                               'strtolower'
        46*       FETCH_DIM_R                                      $37     !7, 1
        47*       SEND_VAR                                                 $37
        48*       DO_ICALL                                         $38     
        49*       SEND_VAR                                                 $38
        50*       SEND_VAR                                                 !1
        51*       DO_ICALL                                         $39     
        52*       ADD                                              ~40     $39, 1
        53*       ASSIGN                                                   !3, ~40
  42    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                                                 
  43    59*       JMPZ                                                     !11, ->64
  44    60*       FETCH_DIM_R                                      $43     !11, 1
        61*       JMPZ                                                     $43, ->64
  45    62*       FETCH_DIM_R                                      $44     !11, 1
        63*       ASSIGN                                                   !10, $44
  48    64*       ISSET_ISEMPTY_VAR                           293601280  ~46     !5
        65*       JMPZ                                                     ~46, ->75
  49    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                                                 
  50    71*       FETCH_DIM_R                                      $48     !4, 0
        72*       JMPZ                                                     $48, ->75
  51    73*       FETCH_DIM_R                                      $49     !4, 0
        74*       ASSIGN                                                   !5, $49
  53    75*       ISSET_ISEMPTY_VAR                           293601280  ~51     !10
        76*       BOOL_NOT                                         ~52     ~51
        77*       JMPZ_EX                                          ~52     ~52, ->81
        78*       ISSET_ISEMPTY_VAR                           293601280  ~53     !3
        79*       BOOL_NOT                                         ~54     ~53
        80*       BOOL                                             ~52     ~54
        81*       JMPZ_EX                                          ~52     ~52, ->84
        82*       ISSET_ISEMPTY_VAR                           293601280  ~55     !5
        83*       BOOL                                             ~52     ~55
        84*       JMPZ                                                     ~52, ->94
  54    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                                                 
  55    90*       FETCH_DIM_R                                      $57     !4, 0
        91*       JMPZ                                                     $57, ->94
  56    92*       FETCH_DIM_R                                      $58     !4, 0
        93*       ASSIGN                                                   !5, $58
  58    94*       ASSIGN                                                   !10, '01'
  60    95*       STRLEN                                           ~61     !10
        96*       IS_EQUAL                                         ~62     1, ~61
        97*       JMPZ                                                     ~62, ->100
  61    98*       CONCAT                                           ~63     '0', !10
        99*       ASSIGN                                                   !10, ~63
  63   100*       STRLEN                                           ~65     !3
       101*       IS_EQUAL                                         ~66     1, ~65
       102*       JMPZ                                                     ~66, ->105
  64   103*       CONCAT                                           ~67     '0', !3
       104*       ASSIGN                                                   !3, ~67
  66   105*       STRLEN                                           ~69     !5
       106*       IS_EQUAL                                         ~70     2, ~69
       107*       JMPZ_EX                                          ~70     ~70, ->110
       108*       IS_SMALLER                                       ~71     20, !5
       109*       BOOL                                             ~70     ~71
       110*       JMPZ                                                     ~70, ->114
  67   111*       CONCAT                                           ~72     '19', !5
       112*       ASSIGN                                                   !5, ~72
       113*       JMP                                                      ->122
  68   114*       STRLEN                                           ~74     !5
       115*       IS_EQUAL                                         ~75     2, ~74
       116*       JMPZ_EX                                          ~75     ~75, ->119
       117*       IS_SMALLER                                       ~76     !5, 20
       118*       BOOL                                             ~75     ~76
       119*       JMPZ                                                     ~75, ->122
  69   120*       CONCAT                                           ~77     '20', !5
       121*       ASSIGN                                                   !5, ~77
  71   122*       INIT_ARRAY                                       ~79     !5, 'year'
  72   123*       ADD_ARRAY_ELEMENT                                ~79     !3, 'month'
  73   124*       ADD_ARRAY_ELEMENT                                ~79     !10, 'day'
       125*       ASSIGN                                                   !12, ~79
  76   126*       ISSET_ISEMPTY_VAR                           293601280  ~81     !5
       127*       JMPZ_EX                                          ~81     ~81, ->130
       128*       ISSET_ISEMPTY_VAR                           293601280  ~82     !3
       129*       BOOL                                             ~81     ~82
       130*       JMPZ_EX                                          ~81     ~81, ->133
       131*       ISSET_ISEMPTY_VAR                           293601280  ~83     !10
       132*       BOOL                                             ~81     ~83
       133*       JMPZ                                                     ~81, ->136
  77   134*       RETURN                                                   <false>
       135*       JMP                                                      ->149
  79   136*       INIT_FCALL                                               'date'
       137*       SEND_VAL                                                 'Y-m-d'
       138*       INIT_FCALL                                               'strtotime'
       139*       FETCH_DIM_R                                      $84     !12, 'year'
       140*       CONCAT                                           ~85     $84, '-'
       141*       FETCH_DIM_R                                      $86     !12, 'month'
       142*       CONCAT                                           ~87     ~85, $86
       143*       CONCAT                                           ~88     ~87, '-01'
       144*       SEND_VAL                                                 ~88
       145*       DO_ICALL                                         $89     
       146*       SEND_VAR                                                 $89
       147*       DO_ICALL                                         $90     
       148*       RETURN                                                   $90
  80   149*     > RETURN                                                   null

End of function find_date

Generated using Vulcan Logic Dumper, using php 7.3.0