3v4l.org

run code in 300+ PHP versions simultaneously
<?php $rows = [ ['`1234567890-=', '~!@#$%^&*()_+'], ['qwertyuiop[]\\', 'QWERTYUIOP{}|'], ['asdfghjkl;\'', 'ASDFGHJKL:"'], ['zxcvbnm,./', 'ZXCVBNM<>?'] ]; $wholeregex = []; foreach($rows as $k => $row) { $num = $k + 1; echo "Row $num\n"; $array = []; foreach($row as $subrow) { $subarray = array_map('ord', str_split($subrow)); $array = array_merge($subarray, $array); } sort($array); echo "\t" . implode( ' ', $array), "\n"; $ret = [$array[0]]; for($i = 1; $i < count($array); $i++) { $num = $array[$i]; if(($array[$i - 1] + 1) == $num) { if( ($i == (count($array) - 1)) || ($array[$i + 1] != ($num + 1)) ) { $ret[] = array_pop($ret) . '-' . $num; } } else { $ret[] = $num; } } echo "\t" . implode( ' ', $ret), "\n"; $regex = '(['; $subregex = implode( '', array_map(function($el) { $vals = explode('-', $el); if(count($vals) == 1) { return chr($vals[0]); } return chr($vals[0]) . '-' . chr($vals[1]); }, $ret)); $regex .= $subregex; $regex .= '])'; echo "\t" . $regex, "\n"; $wholeregex[] = $regex; } $finalregex = '%' . implode('|', $wholeregex) . '%'; $finalregex = str_replace('(-', '\(-', $finalregex); echo $finalregex, "\n"; echo strlen($finalregex), "\n"; $input = "a"; preg_match($finalregex, $input, $m); echo array_flip($m)[$input];
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 101
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 101
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 28
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 28
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 72
Branch analysis from position: 72
2 jumps found. (Code = 44) Position 1 = 75, Position 2 = 44
Branch analysis from position: 75
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 51, Position 2 = 69
Branch analysis from position: 51
2 jumps found. (Code = 47) Position 1 = 55, Position 2 = 60
Branch analysis from position: 55
2 jumps found. (Code = 43) Position 1 = 61, Position 2 = 68
Branch analysis from position: 61
1 jumps found. (Code = 42) Position 1 = 71
Branch analysis from position: 71
2 jumps found. (Code = 44) Position 1 = 75, Position 2 = 44
Branch analysis from position: 75
Branch analysis from position: 44
Branch analysis from position: 68
Branch analysis from position: 60
Branch analysis from position: 69
2 jumps found. (Code = 44) Position 1 = 75, Position 2 = 44
Branch analysis from position: 75
Branch analysis from position: 44
Branch analysis from position: 28
Branch analysis from position: 101
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 101
filename:       /in/ZXs6M
function name:  (null)
number of ops:  132
compiled vars:  !0 = $rows, !1 = $wholeregex, !2 = $row, !3 = $k, !4 = $num, !5 = $array, !6 = $subrow, !7 = $subarray, !8 = $ret, !9 = $i, !10 = $regex, !11 = $subregex, !12 = $finalregex, !13 = $input, !14 = $m
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    9     1        ASSIGN                                                   !1, <array>
   10     2      > FE_RESET_R                                       $17     !0, ->101
          3    > > FE_FETCH_R                                       ~18     $17, !2, ->101
          4    >   ASSIGN                                                   !3, ~18
   11     5        ADD                                              ~20     !3, 1
          6        ASSIGN                                                   !4, ~20
   12     7        ROPE_INIT                                     3  ~23     'Row+'
          8        ROPE_ADD                                      1  ~23     ~23, !4
          9        ROPE_END                                      2  ~22     ~23, '%0A'
         10        ECHO                                                     ~22
   13    11        ASSIGN                                                   !5, <array>
   14    12      > FE_RESET_R                                       $26     !2, ->28
         13    > > FE_FETCH_R                                               $26, !6, ->28
   15    14    >   INIT_FCALL                                               'array_map'
         15        SEND_VAL                                                 'ord'
         16        INIT_FCALL                                               'str_split'
         17        SEND_VAR                                                 !6
         18        DO_ICALL                                         $27     
         19        SEND_VAR                                                 $27
         20        DO_ICALL                                         $28     
         21        ASSIGN                                                   !7, $28
   16    22        INIT_FCALL                                               'array_merge'
         23        SEND_VAR                                                 !7
         24        SEND_VAR                                                 !5
         25        DO_ICALL                                         $30     
         26        ASSIGN                                                   !5, $30
   14    27      > JMP                                                      ->13
         28    >   FE_FREE                                                  $26
   18    29        INIT_FCALL                                               'sort'
         30        SEND_REF                                                 !5
         31        DO_ICALL                                                 
   20    32        INIT_FCALL                                               'implode'
         33        SEND_VAL                                                 '+'
         34        SEND_VAR                                                 !5
         35        DO_ICALL                                         $33     
         36        CONCAT                                           ~34     '%09', $33
         37        ECHO                                                     ~34
         38        ECHO                                                     '%0A'
   22    39        FETCH_DIM_R                                      ~35     !5, 0
         40        INIT_ARRAY                                       ~36     ~35
         41        ASSIGN                                                   !8, ~36
   23    42        ASSIGN                                                   !9, 1
         43      > JMP                                                      ->72
   24    44    >   FETCH_DIM_R                                      ~39     !5, !9
         45        ASSIGN                                                   !4, ~39
   25    46        SUB                                              ~41     !9, 1
         47        FETCH_DIM_R                                      ~42     !5, ~41
         48        ADD                                              ~43     ~42, 1
         49        IS_EQUAL                                                 !4, ~43
         50      > JMPZ                                                     ~44, ->69
   26    51    >   COUNT                                            ~45     !5
         52        SUB                                              ~46     ~45, 1
         53        IS_EQUAL                                         ~47     !9, ~46
         54      > JMPNZ_EX                                         ~47     ~47, ->60
         55    >   ADD                                              ~48     !9, 1
         56        FETCH_DIM_R                                      ~49     !5, ~48
         57        ADD                                              ~50     !4, 1
         58        IS_NOT_EQUAL                                     ~51     ~49, ~50
         59        BOOL                                             ~47     ~51
         60    > > JMPZ                                                     ~47, ->68
   27    61    >   INIT_FCALL                                               'array_pop'
         62        SEND_REF                                                 !8
         63        DO_ICALL                                         $53     
         64        CONCAT                                           ~54     $53, '-'
         65        CONCAT                                           ~55     ~54, !4
         66        ASSIGN_DIM                                               !8
         67        OP_DATA                                                  ~55
         68    > > JMP                                                      ->71
   30    69    >   ASSIGN_DIM                                               !8
         70        OP_DATA                                                  !4
   23    71    >   PRE_INC                                                  !9
         72    >   COUNT                                            ~58     !5
         73        IS_SMALLER                                               !9, ~58
         74      > JMPNZ                                                    ~59, ->44
   34    75    >   INIT_FCALL                                               'implode'
         76        SEND_VAL                                                 '+'
         77        SEND_VAR                                                 !8
         78        DO_ICALL                                         $60     
         79        CONCAT                                           ~61     '%09', $60
         80        ECHO                                                     ~61
         81        ECHO                                                     '%0A'
   36    82        ASSIGN                                                   !10, '%28%5B'
   37    83        INIT_FCALL                                               'implode'
         84        SEND_VAL                                                 ''
         85        INIT_FCALL                                               'array_map'
         86        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FZXs6M%3A37%240'
   43    87        SEND_VAL                                                 ~63
         88        SEND_VAR                                                 !8
         89        DO_ICALL                                         $64     
         90        SEND_VAR                                                 $64
         91        DO_ICALL                                         $65     
   37    92        ASSIGN                                                   !11, $65
   44    93        ASSIGN_OP                                     8          !10, !11
   45    94        ASSIGN_OP                                     8          !10, '%5D%29'
   47    95        CONCAT                                           ~69     '%09', !10
         96        ECHO                                                     ~69
         97        ECHO                                                     '%0A'
   48    98        ASSIGN_DIM                                               !1
         99        OP_DATA                                                  !10
   10   100      > JMP                                                      ->3
        101    >   FE_FREE                                                  $17
   51   102        INIT_FCALL                                               'implode'
        103        SEND_VAL                                                 '%7C'
        104        SEND_VAR                                                 !1
        105        DO_ICALL                                         $71     
        106        CONCAT                                           ~72     '%25', $71
        107        CONCAT                                           ~73     ~72, '%25'
        108        ASSIGN                                                   !12, ~73
   52   109        INIT_FCALL                                               'str_replace'
        110        SEND_VAL                                                 '%28-'
        111        SEND_VAL                                                 '%5C%28-'
        112        SEND_VAR                                                 !12
        113        DO_ICALL                                         $75     
        114        ASSIGN                                                   !12, $75
   54   115        ECHO                                                     !12
        116        ECHO                                                     '%0A'
   55   117        STRLEN                                           ~77     !12
        118        ECHO                                                     ~77
        119        ECHO                                                     '%0A'
   57   120        ASSIGN                                                   !13, 'a'
   58   121        INIT_FCALL                                               'preg_match'
        122        SEND_VAR                                                 !12
        123        SEND_VAR                                                 !13
        124        SEND_REF                                                 !14
        125        DO_ICALL                                                 
   59   126        INIT_FCALL                                               'array_flip'
        127        SEND_VAR                                                 !14
        128        DO_ICALL                                         $80     
        129        FETCH_DIM_R                                      ~81     $80, !13
        130        ECHO                                                     ~81
        131      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FZXs6M%3A37%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZXs6M
function name:  {closure}
number of ops:  26
compiled vars:  !0 = $el, !1 = $vals
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
   38     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '-'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5        ASSIGN                                                   !1, $2
   39     6        COUNT                                            ~4      !1
          7        IS_EQUAL                                                 ~4, 1
          8      > JMPZ                                                     ~5, ->14
   40     9    >   INIT_FCALL                                               'chr'
         10        FETCH_DIM_R                                      ~6      !1, 0
         11        SEND_VAL                                                 ~6
         12        DO_ICALL                                         $7      
         13      > RETURN                                                   $7
   42    14    >   INIT_FCALL                                               'chr'
         15        FETCH_DIM_R                                      ~8      !1, 0
         16        SEND_VAL                                                 ~8
         17        DO_ICALL                                         $9      
         18        CONCAT                                           ~10     $9, '-'
         19        INIT_FCALL                                               'chr'
         20        FETCH_DIM_R                                      ~11     !1, 1
         21        SEND_VAL                                                 ~11
         22        DO_ICALL                                         $12     
         23        CONCAT                                           ~13     ~10, $12
         24      > RETURN                                                   ~13
   43    25*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FZXs6M%3A37%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
179.19 ms | 1408 KiB | 35 Q