3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = /*$_GET['input'];*/ "Timothy Gentet-O'Brien"; $simpleBuilder = simpleBuilder($string); $advancedBuilder = advancedBuilder($simpleBuilder); echo "<script>console.log('advancedBuilder: ' + advancedBuilder);</script>"; echo "\r\n"; echo $advancedBuilder; // simpleBuilder() takes in an arrray of strings or a comma separated string, this should return // an Array of basic RegEx's function simpleBuilder($input) { // Check to see if it is an array, if it is not then we use .split(',') to convert it to an array. $input = is_array($input) ? $input : explode(',', $input); $simpleRegEx = []; // Iterate over all of the values in the array. for ($i = 0; $i < count($input); $i++) { // Set simpleRegEx[$i] to '' to ensure the code doesn't set it to "undefinedXXXX" $simpleRegEx[$i] = ''; // Run ltrim() and rtrim() on the current string ton ensure we have to extra and unneeded white spaces. $input[$i] = ltrim(rtrim($input[$i])); // Iterate over the current string to work out what each character is and assign simpleRegEx[$i] the relevant RegEx character for ($j = 0; $j < count($input[$i]); $j++) { if (preg_match('/[ \f\n\r\t\v\u00a0\u1680\u180e\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]/', $input[$i][$j])) { $simpleRegEx[$i] += '\\s'; } else if (preg_match('/[0-9]/', $input[$i][$j])) { $simpleRegEx[$i] += '\\d'; } else if (preg_match('/[A-Za-z0-9_]/', $input[$i][$j])) { $simpleRegEx[$i] += '\\w'; } else if (preg_match('/[^A-Za-z0-9_]/', $input[$i][$j])) { $simpleRegEx[$i] += '\\W'; } else if (preg_match('/[^ \f\n\r\t\v\u00a0\u1680\u180e\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]/', $input[$i][$j])) { $simpleRegEx[$i] += '\\S'; } } } // Return the completed Array, which should look something like: ['\w\w\w\w\d\d\d','\w\w\w'] return $simpleRegEx; } // advancedBuilder() takes the output from simpleBuilder(), which is an Array of RegEx Strings, this should return // a more Array of complex set of RegEx's function advancedBuilder($simpleRegEx) { $prev = $curr = $next = null; $rcount = 1; $advancedRegex = []; // Iterate over the array for ($t = 0; $t < count($simpleRegEx); $t++) { // Again set advancedRegex[$t] to '' to ensure the code doesn't set it to "undefinedXXXX" $advancedRegex[$t] = ''; // Iterate over the current string, check the current, next and previous characters to // calculate whether or not we should be joining these, if everything if good, it should // then add the RegEx character '\d' and work out how many times this appears, it should // then output something like: '\d{4}'. for ($s = 0; $s < count($simpleRegEx[$t]); $s += 2) { $curr = $simpleRegEx[$t][$s] + $simpleRegEx[$t][$s + 1]; $next = $simpleRegEx[$t][$s + 2] + $simpleRegEx[$t][$s + 3]; $prev = $simpleRegEx[$t][$s - 2] + $simpleRegEx[$t][$s - 1]; if ($curr == $next) { if ($prev != $curr) { $advancedRegex[$t] += $curr; } $rcount += 1; } else { $advancedRegex[$t] += ($rcount == 1 ? $curr : '{' + $rcount + '}'); $rcount = 1; } } } // The Array of RegEx's, this should look something like: ["\w{7}\d{3}", "\w{3}"] // so we use .join('|') to add in an OR operator and add a caret and a dollar symbol // to show the start and end of the newly formed string to return a full RegEx $advancedRegex = '^' + join('|', $advancedRegex) + '$'; return $advancedRegex; } ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/r9HAo
function name:  (null)
number of ops:  13
compiled vars:  !0 = $string, !1 = $simpleBuilder, !2 = $advancedBuilder
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'Timothy+Gentet-O%27Brien'
    5     1        INIT_FCALL_BY_NAME                                       'simpleBuilder'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $4      
          4        ASSIGN                                                   !1, $4
    6     5        INIT_FCALL_BY_NAME                                       'advancedBuilder'
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0  $6      
          8        ASSIGN                                                   !2, $6
    7     9        ECHO                                                     '%3Cscript%3Econsole.log%28%27advancedBuilder%3A+%27+%2B+advancedBuilder%29%3B%3C%2Fscript%3E'
    8    10        ECHO                                                     '%0D%0A'
    9    11        ECHO                                                     !2
   78    12      > RETURN                                                   1

Function simplebuilder:
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 = 10
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 82
Branch analysis from position: 82
2 jumps found. (Code = 44) Position 1 = 85, Position 2 = 14
Branch analysis from position: 85
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 77
Branch analysis from position: 77
2 jumps found. (Code = 44) Position 1 = 81, Position 2 = 27
Branch analysis from position: 81
2 jumps found. (Code = 44) Position 1 = 85, Position 2 = 14
Branch analysis from position: 85
Branch analysis from position: 14
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 37
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 76
Branch analysis from position: 76
2 jumps found. (Code = 44) Position 1 = 81, Position 2 = 27
Branch analysis from position: 81
Branch analysis from position: 27
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 47
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 76
Branch analysis from position: 76
Branch analysis from position: 47
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 57
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 76
Branch analysis from position: 76
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 64, Position 2 = 67
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 76
Branch analysis from position: 76
Branch analysis from position: 67
2 jumps found. (Code = 43) Position 1 = 74, Position 2 = 76
Branch analysis from position: 74
2 jumps found. (Code = 44) Position 1 = 81, Position 2 = 27
Branch analysis from position: 81
Branch analysis from position: 27
Branch analysis from position: 76
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 82
Branch analysis from position: 82
filename:       /in/r9HAo
function name:  simpleBuilder
number of ops:  87
compiled vars:  !0 = $input, !1 = $simpleRegEx, !2 = $i, !3 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   15     1        TYPE_CHECK                                  128          !0
          2      > JMPZ                                                     ~4, ->5
          3    >   QM_ASSIGN                                        ~5      !0
          4      > JMP                                                      ->10
          5    >   INIT_FCALL                                               'explode'
          6        SEND_VAL                                                 '%2C'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $6      
          9        QM_ASSIGN                                        ~5      $6
         10    >   ASSIGN                                                   !0, ~5
   16    11        ASSIGN                                                   !1, <array>
   18    12        ASSIGN                                                   !2, 0
         13      > JMP                                                      ->82
   20    14    >   ASSIGN_DIM                                               !1, !2
         15        OP_DATA                                                  ''
   22    16        INIT_FCALL                                               'ltrim'
         17        INIT_FCALL                                               'rtrim'
         18        FETCH_DIM_R                                      ~12     !0, !2
         19        SEND_VAL                                                 ~12
         20        DO_ICALL                                         $13     
         21        SEND_VAR                                                 $13
         22        DO_ICALL                                         $14     
         23        ASSIGN_DIM                                               !0, !2
         24        OP_DATA                                                  $14
   24    25        ASSIGN                                                   !3, 0
         26      > JMP                                                      ->77
   25    27    >   INIT_FCALL                                               'preg_match'
         28        SEND_VAL                                                 '%2F%5B+%5Cf%5Cn%5Cr%5Ct%5Cv%5Cu00a0%5Cu1680%5Cu180e%5Cu2000-%5Cu200a%5Cu2028%5Cu2029%5Cu202f%5Cu205f%5Cu3000%5Cufeff%5D%2F'
         29        FETCH_DIM_R                                      ~16     !0, !2
         30        FETCH_DIM_R                                      ~17     ~16, !3
         31        SEND_VAL                                                 ~17
         32        DO_ICALL                                         $18     
         33      > JMPZ                                                     $18, ->37
   26    34    >   ASSIGN_DIM_OP                +=               1          !1, !2
         35        OP_DATA                                                  '%5Cs'
         36      > JMP                                                      ->76
   27    37    >   INIT_FCALL                                               'preg_match'
         38        SEND_VAL                                                 '%2F%5B0-9%5D%2F'
         39        FETCH_DIM_R                                      ~20     !0, !2
         40        FETCH_DIM_R                                      ~21     ~20, !3
         41        SEND_VAL                                                 ~21
         42        DO_ICALL                                         $22     
         43      > JMPZ                                                     $22, ->47
   28    44    >   ASSIGN_DIM_OP                +=               1          !1, !2
         45        OP_DATA                                                  '%5Cd'
         46      > JMP                                                      ->76
   29    47    >   INIT_FCALL                                               'preg_match'
         48        SEND_VAL                                                 '%2F%5BA-Za-z0-9_%5D%2F'
         49        FETCH_DIM_R                                      ~24     !0, !2
         50        FETCH_DIM_R                                      ~25     ~24, !3
         51        SEND_VAL                                                 ~25
         52        DO_ICALL                                         $26     
         53      > JMPZ                                                     $26, ->57
   30    54    >   ASSIGN_DIM_OP                +=               1          !1, !2
         55        OP_DATA                                                  '%5Cw'
         56      > JMP                                                      ->76
   31    57    >   INIT_FCALL                                               'preg_match'
         58        SEND_VAL                                                 '%2F%5B%5EA-Za-z0-9_%5D%2F'
         59        FETCH_DIM_R                                      ~28     !0, !2
         60        FETCH_DIM_R                                      ~29     ~28, !3
         61        SEND_VAL                                                 ~29
         62        DO_ICALL                                         $30     
         63      > JMPZ                                                     $30, ->67
   32    64    >   ASSIGN_DIM_OP                +=               1          !1, !2
         65        OP_DATA                                                  '%5CW'
         66      > JMP                                                      ->76
   33    67    >   INIT_FCALL                                               'preg_match'
         68        SEND_VAL                                                 '%2F%5B%5E+%5Cf%5Cn%5Cr%5Ct%5Cv%5Cu00a0%5Cu1680%5Cu180e%5Cu2000-%5Cu200a%5Cu2028%5Cu2029%5Cu202f%5Cu205f%5Cu3000%5Cufeff%5D%2F'
         69        FETCH_DIM_R                                      ~32     !0, !2
         70        FETCH_DIM_R                                      ~33     ~32, !3
         71        SEND_VAL                                                 ~33
         72        DO_ICALL                                         $34     
         73      > JMPZ                                                     $34, ->76
   34    74    >   ASSIGN_DIM_OP                +=               1          !1, !2
         75        OP_DATA                                                  '%5CS'
   24    76    >   PRE_INC                                                  !3
         77    >   FETCH_DIM_R                                      ~37     !0, !2
         78        COUNT                                            ~38     ~37
         79        IS_SMALLER                                               !3, ~38
         80      > JMPNZ                                                    ~39, ->27
   18    81    >   PRE_INC                                                  !2
         82    >   COUNT                                            ~41     !0
         83        IS_SMALLER                                               !2, ~41
         84      > JMPNZ                                                    ~42, ->14
   39    85    > > RETURN                                                   !1
   40    86*     > RETURN                                                   null

End of function simplebuilder

Function advancedbuilder:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
2 jumps found. (Code = 44) Position 1 = 62, Position 2 = 8
Branch analysis from position: 62
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 54
Branch analysis from position: 54
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 12
Branch analysis from position: 58
2 jumps found. (Code = 44) Position 1 = 62, Position 2 = 8
Branch analysis from position: 62
Branch analysis from position: 8
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 43
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 41
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 12
Branch analysis from position: 58
Branch analysis from position: 12
Branch analysis from position: 41
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 47
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 12
Branch analysis from position: 58
Branch analysis from position: 12
Branch analysis from position: 47
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 12
Branch analysis from position: 58
Branch analysis from position: 12
filename:       /in/r9HAo
function name:  advancedBuilder
number of ops:  71
compiled vars:  !0 = $simpleRegEx, !1 = $prev, !2 = $curr, !3 = $next, !4 = $rcount, !5 = $advancedRegex, !6 = $t, !7 = $s
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   RECV                                             !0      
   45     1        ASSIGN                                           ~8      !3, null
          2        ASSIGN                                           ~9      !2, ~8
          3        ASSIGN                                                   !1, ~9
   46     4        ASSIGN                                                   !4, 1
   47     5        ASSIGN                                                   !5, <array>
   50     6        ASSIGN                                                   !6, 0
          7      > JMP                                                      ->59
   52     8    >   ASSIGN_DIM                                               !5, !6
          9        OP_DATA                                                  ''
   57    10        ASSIGN                                                   !7, 0
         11      > JMP                                                      ->54
   58    12    >   FETCH_DIM_R                                      ~16     !0, !6
         13        FETCH_DIM_R                                      ~17     ~16, !7
         14        ADD                                              ~19     !7, 1
         15        FETCH_DIM_R                                      ~18     !0, !6
         16        FETCH_DIM_R                                      ~20     ~18, ~19
         17        ADD                                              ~21     ~17, ~20
         18        ASSIGN                                                   !2, ~21
   59    19        ADD                                              ~24     !7, 2
         20        FETCH_DIM_R                                      ~23     !0, !6
         21        FETCH_DIM_R                                      ~25     ~23, ~24
         22        ADD                                              ~27     !7, 3
         23        FETCH_DIM_R                                      ~26     !0, !6
         24        FETCH_DIM_R                                      ~28     ~26, ~27
         25        ADD                                              ~29     ~25, ~28
         26        ASSIGN                                                   !3, ~29
   60    27        SUB                                              ~32     !7, 2
         28        FETCH_DIM_R                                      ~31     !0, !6
         29        FETCH_DIM_R                                      ~33     ~31, ~32
         30        SUB                                              ~35     !7, 1
         31        FETCH_DIM_R                                      ~34     !0, !6
         32        FETCH_DIM_R                                      ~36     ~34, ~35
         33        ADD                                              ~37     ~33, ~36
         34        ASSIGN                                                   !1, ~37
   61    35        IS_EQUAL                                                 !2, !3
         36      > JMPZ                                                     ~39, ->43
   62    37    >   IS_NOT_EQUAL                                             !1, !2
         38      > JMPZ                                                     ~40, ->41
   63    39    >   ASSIGN_DIM_OP                +=               1          !5, !6
         40        OP_DATA                                                  !2
   65    41    >   ASSIGN_OP                                     1          !4, 1
         42      > JMP                                                      ->53
   67    43    >   IS_EQUAL                                                 !4, 1
         44      > JMPZ                                                     ~44, ->47
         45    >   QM_ASSIGN                                        ~45     !2
         46      > JMP                                                      ->50
         47    >   ADD                                              ~46     '%7B', !4
         48        ADD                                              ~47     ~46, '%7D'
         49        QM_ASSIGN                                        ~45     ~47
         50    >   ASSIGN_DIM_OP                +=               1          !5, !6
         51        OP_DATA                                                  ~45
   68    52        ASSIGN                                                   !4, 1
   57    53    >   ASSIGN_OP                                     1          !7, 2
         54    >   FETCH_DIM_R                                      ~50     !0, !6
         55        COUNT                                            ~51     ~50
         56        IS_SMALLER                                               !7, ~51
         57      > JMPNZ                                                    ~52, ->12
   50    58    >   PRE_INC                                                  !6
         59    >   COUNT                                            ~54     !0
         60        IS_SMALLER                                               !6, ~54
         61      > JMPNZ                                                    ~55, ->8
   75    62    >   INIT_FCALL                                               'join'
         63        SEND_VAL                                                 '%7C'
         64        SEND_VAR                                                 !5
         65        DO_ICALL                                         $56     
         66        ADD                                              ~57     '%5E', $56
         67        ADD                                              ~58     ~57, '%24'
         68        ASSIGN                                                   !5, ~58
   76    69      > RETURN                                                   !5
   77    70*     > RETURN                                                   null

End of function advancedbuilder

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
181.51 ms | 1412 KiB | 23 Q