3v4l.org

run code in 300+ PHP versions simultaneously
<?php function gdr_encode($val) { $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!='; $base = strlen($chars); $str = ''; while ($val > 0) { $str = $chars[$val % $base] . $str; $val = (int)($val / $base); } return $str; } function gdr_decode($str) { $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!='; $base = strlen($chars); $map = array(); for ($i=0; $i<$base; $i++) { $map[$chars[$i]] = $i; } $val = 0; for ($i=0; $i<strlen($str); $i++) { $val *= $base; $val += (int)$map[$str[$i]]; } return $val; } $vals = array(0, 1, 99, 100, 255, 256, 999, 1000, 9999, 10000, 65535, 65536, 99999, 100000, 999999, 1000000, 4294967295, 4294967296); foreach ($vals as $val) { $enc = gdr_encode($val); $dec = gdr_decode($enc); if ($dec !== $val) { echo "ERROR: $val => $enc => $dec\n"; } else if (strlen($enc)+2 > strlen($val)) { echo "\"$enc\" $val WORSE\n"; } else if (strlen($enc)+2 == strlen($val)) { echo "\"$enc\" $val EQUAL\n"; } else { echo "\"$enc\" $val\n"; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 53
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 53
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 22
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 34
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 46
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 53
filename:       /in/FVRQ3
function name:  (null)
number of ops:  55
compiled vars:  !0 = $vals, !1 = $val, !2 = $enc, !3 = $dec
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   ASSIGN                                                   !0, <array>
   30     1      > FE_RESET_R                                       $5      !0, ->53
          2    > > FE_FETCH_R                                               $5, !1, ->53
   31     3    >   INIT_FCALL                                               'gdr_encode'
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $6      
          6        ASSIGN                                                   !2, $6
   32     7        INIT_FCALL                                               'gdr_decode'
          8        SEND_VAR                                                 !2
          9        DO_FCALL                                      0  $8      
         10        ASSIGN                                                   !3, $8
   33    11        IS_NOT_IDENTICAL                                         !3, !1
         12      > JMPZ                                                     ~10, ->22
   34    13    >   ROPE_INIT                                     7  ~12     'ERROR%3A+'
         14        ROPE_ADD                                      1  ~12     ~12, !1
         15        ROPE_ADD                                      2  ~12     ~12, '+%3D%3E+'
         16        ROPE_ADD                                      3  ~12     ~12, !2
         17        ROPE_ADD                                      4  ~12     ~12, '+%3D%3E+'
         18        ROPE_ADD                                      5  ~12     ~12, !3
         19        ROPE_END                                      6  ~11     ~12, '%0A'
         20        ECHO                                                     ~11
         21      > JMP                                                      ->52
   35    22    >   STRLEN                                           ~16     !2
         23        ADD                                              ~17     ~16, 2
         24        STRLEN                                           ~18     !1
         25        IS_SMALLER                                               ~18, ~17
         26      > JMPZ                                                     ~19, ->34
   36    27    >   ROPE_INIT                                     5  ~21     '%22'
         28        ROPE_ADD                                      1  ~21     ~21, !2
         29        ROPE_ADD                                      2  ~21     ~21, '%22+'
         30        ROPE_ADD                                      3  ~21     ~21, !1
         31        ROPE_END                                      4  ~20     ~21, '+WORSE%0A'
         32        ECHO                                                     ~20
         33      > JMP                                                      ->52
   37    34    >   STRLEN                                           ~24     !2
         35        ADD                                              ~25     ~24, 2
         36        STRLEN                                           ~26     !1
         37        IS_EQUAL                                                 ~25, ~26
         38      > JMPZ                                                     ~27, ->46
   38    39    >   ROPE_INIT                                     5  ~29     '%22'
         40        ROPE_ADD                                      1  ~29     ~29, !2
         41        ROPE_ADD                                      2  ~29     ~29, '%22+'
         42        ROPE_ADD                                      3  ~29     ~29, !1
         43        ROPE_END                                      4  ~28     ~29, '+EQUAL%0A'
         44        ECHO                                                     ~28
         45      > JMP                                                      ->52
   40    46    >   ROPE_INIT                                     5  ~33     '%22'
         47        ROPE_ADD                                      1  ~33     ~33, !2
         48        ROPE_ADD                                      2  ~33     ~33, '%22+'
         49        ROPE_ADD                                      3  ~33     ~33, !1
         50        ROPE_END                                      4  ~32     ~33, '%0A'
         51        ECHO                                                     ~32
   30    52    > > JMP                                                      ->2
         53    >   FE_FREE                                                  $5
   42    54      > RETURN                                                   1

Function gdr_encode:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 6
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 6
Branch analysis from position: 15
Branch analysis from position: 6
filename:       /in/FVRQ3
function name:  gdr_encode
number of ops:  17
compiled vars:  !0 = $val, !1 = $chars, !2 = $base, !3 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789%21%3D'
    5     2        STRLEN                                           ~5      !1
          3        ASSIGN                                                   !2, ~5
    6     4        ASSIGN                                                   !3, ''
    7     5      > JMP                                                      ->13
    8     6    >   MOD                                              ~8      !0, !2
          7        FETCH_DIM_R                                      ~9      !1, ~8
          8        CONCAT                                           ~10     ~9, !3
          9        ASSIGN                                                   !3, ~10
    9    10        DIV                                              ~12     !0, !2
         11        CAST                                          4  ~13     ~12
         12        ASSIGN                                                   !0, ~13
    7    13    >   IS_SMALLER                                               0, !0
         14      > JMPNZ                                                    ~15, ->6
   11    15    > > RETURN                                                   !3
   12    16*     > RETURN                                                   null

End of function gdr_encode

Function gdr_decode:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 7
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 16
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 16
Branch analysis from position: 25
Branch analysis from position: 16
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 7
Branch analysis from position: 13
Branch analysis from position: 7
filename:       /in/FVRQ3
function name:  gdr_decode
number of ops:  27
compiled vars:  !0 = $str, !1 = $chars, !2 = $base, !3 = $map, !4 = $i, !5 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        ASSIGN                                                   !1, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789%21%3D'
   16     2        STRLEN                                           ~7      !1
          3        ASSIGN                                                   !2, ~7
   17     4        ASSIGN                                                   !3, <array>
   18     5        ASSIGN                                                   !4, 0
          6      > JMP                                                      ->11
   19     7    >   FETCH_DIM_R                                      ~11     !1, !4
          8        ASSIGN_DIM                                               !3, ~11
          9        OP_DATA                                                  !4
   18    10        PRE_INC                                                  !4
         11    >   IS_SMALLER                                               !4, !2
         12      > JMPNZ                                                    ~14, ->7
   21    13    >   ASSIGN                                                   !5, 0
   22    14        ASSIGN                                                   !4, 0
         15      > JMP                                                      ->22
   23    16    >   ASSIGN_OP                                     3          !5, !2
   24    17        FETCH_DIM_R                                      ~18     !0, !4
         18        FETCH_DIM_R                                      ~19     !3, ~18
         19        CAST                                          4  ~20     ~19
         20        ASSIGN_OP                                     1          !5, ~20
   22    21        PRE_INC                                                  !4
         22    >   STRLEN                                           ~23     !0
         23        IS_SMALLER                                               !4, ~23
         24      > JMPNZ                                                    ~24, ->16
   26    25    > > RETURN                                                   !5
   27    26*     > RETURN                                                   null

End of function gdr_decode

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.21 ms | 1407 KiB | 15 Q