3v4l.org

run code in 300+ PHP versions simultaneously
<?php function gdr_encode($val) { // all characters that json encode without escaping $chrs = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 !#$%&\'()*+,-.:;<=>?@[]^_`{|}~'; $base = strlen($chrs); $str = ''; while ($val > 0) { $str = $chrs[$val % $base] . $str; $val = (int)($val / $base); } return $str; } function gdr_decode($str) { // all characters that json encode without escaping $chrs = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 !#$%&\'()*+,-.:;<=>?@[]^_`{|}~'; $base = strlen($chrs); $map = array(); for ($i=0; $i<$base; $i++) { $map[$chrs[$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, 500000, 999999, 1000000, 4294967295, 4294967296); foreach ($vals as $val) { $enc = gdr_encode($val); $dec = gdr_decode($enc); $dlt = strlen($enc)+2 - strlen($val); echo sprintf("%2d %7s %10d\n", $dlt, "\"$enc\"", $dec); if ($dec !== $val) { echo "ERROR: $val => $enc => $dec\n"; } else if (strlen($enc)+2 > strlen($val)) { echo "+$dlt \"$enc\" $val\n"; } else if (strlen($enc)+2 == strlen($val)) { echo "== \"$enc\" $val\n"; } else { echo "$dlt \"$enc\" $val\n"; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 71
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 71
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 37
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 51
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
Branch analysis from position: 51
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 63
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
Branch analysis from position: 63
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 71
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 71
filename:       /in/B38sS
function name:  (null)
number of ops:  73
compiled vars:  !0 = $vals, !1 = $val, !2 = $enc, !3 = $dec, !4 = $dlt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   ASSIGN                                                   !0, <array>
   32     1      > FE_RESET_R                                       $6      !0, ->71
          2    > > FE_FETCH_R                                               $6, !1, ->71
   33     3    >   INIT_FCALL                                               'gdr_encode'
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $7      
          6        ASSIGN                                                   !2, $7
   34     7        INIT_FCALL                                               'gdr_decode'
          8        SEND_VAR                                                 !2
          9        DO_FCALL                                      0  $9      
         10        ASSIGN                                                   !3, $9
   35    11        STRLEN                                           ~11     !2
         12        ADD                                              ~12     ~11, 2
         13        STRLEN                                           ~13     !1
         14        SUB                                              ~14     ~12, ~13
         15        ASSIGN                                                   !4, ~14
   36    16        INIT_FCALL                                               'sprintf'
         17        SEND_VAL                                                 '%252d+%257s+%2510d%0A'
         18        SEND_VAR                                                 !4
         19        ROPE_INIT                                     3  ~17     '%22'
         20        ROPE_ADD                                      1  ~17     ~17, !2
         21        ROPE_END                                      2  ~16     ~17, '%22'
         22        SEND_VAL                                                 ~16
         23        SEND_VAR                                                 !3
         24        DO_ICALL                                         $19     
         25        ECHO                                                     $19
   37    26        IS_NOT_IDENTICAL                                         !3, !1
         27      > JMPZ                                                     ~20, ->37
   38    28    >   ROPE_INIT                                     7  ~22     'ERROR%3A+'
         29        ROPE_ADD                                      1  ~22     ~22, !1
         30        ROPE_ADD                                      2  ~22     ~22, '+%3D%3E+'
         31        ROPE_ADD                                      3  ~22     ~22, !2
         32        ROPE_ADD                                      4  ~22     ~22, '+%3D%3E+'
         33        ROPE_ADD                                      5  ~22     ~22, !3
         34        ROPE_END                                      6  ~21     ~22, '%0A'
         35        ECHO                                                     ~21
         36      > JMP                                                      ->70
   39    37    >   STRLEN                                           ~26     !2
         38        ADD                                              ~27     ~26, 2
         39        STRLEN                                           ~28     !1
         40        IS_SMALLER                                               ~28, ~27
         41      > JMPZ                                                     ~29, ->51
   40    42    >   ROPE_INIT                                     7  ~31     '%2B'
         43        ROPE_ADD                                      1  ~31     ~31, !4
         44        ROPE_ADD                                      2  ~31     ~31, '+%22'
         45        ROPE_ADD                                      3  ~31     ~31, !2
         46        ROPE_ADD                                      4  ~31     ~31, '%22+'
         47        ROPE_ADD                                      5  ~31     ~31, !1
         48        ROPE_END                                      6  ~30     ~31, '%0A'
         49        ECHO                                                     ~30
         50      > JMP                                                      ->70
   41    51    >   STRLEN                                           ~35     !2
         52        ADD                                              ~36     ~35, 2
         53        STRLEN                                           ~37     !1
         54        IS_EQUAL                                                 ~36, ~37
         55      > JMPZ                                                     ~38, ->63
   42    56    >   ROPE_INIT                                     5  ~40     '%3D%3D+%22'
         57        ROPE_ADD                                      1  ~40     ~40, !2
         58        ROPE_ADD                                      2  ~40     ~40, '%22+'
         59        ROPE_ADD                                      3  ~40     ~40, !1
         60        ROPE_END                                      4  ~39     ~40, '%0A'
         61        ECHO                                                     ~39
         62      > JMP                                                      ->70
   44    63    >   ROPE_INIT                                     6  ~44     !4
         64        ROPE_ADD                                      1  ~44     ~44, '+%22'
         65        ROPE_ADD                                      2  ~44     ~44, !2
         66        ROPE_ADD                                      3  ~44     ~44, '%22+'
         67        ROPE_ADD                                      4  ~44     ~44, !1
         68        ROPE_END                                      5  ~43     ~44, '%0A'
         69        ECHO                                                     ~43
   32    70    > > JMP                                                      ->2
         71    >   FE_FREE                                                  $6
   46    72      > 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/B38sS
function name:  gdr_encode
number of ops:  17
compiled vars:  !0 = $val, !1 = $chrs, !2 = $base, !3 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+%21%23%24%25%26%27%28%29%2A%2B%2C-.%3A%3B%3C%3D%3E%3F%40%5B%5D%5E_%60%7B%7C%7D%7E'
    6     2        STRLEN                                           ~5      !1
          3        ASSIGN                                                   !2, ~5
    7     4        ASSIGN                                                   !3, ''
    8     5      > JMP                                                      ->13
    9     6    >   MOD                                              ~8      !0, !2
          7        FETCH_DIM_R                                      ~9      !1, ~8
          8        CONCAT                                           ~10     ~9, !3
          9        ASSIGN                                                   !3, ~10
   10    10        DIV                                              ~12     !0, !2
         11        CAST                                          4  ~13     ~12
         12        ASSIGN                                                   !0, ~13
    8    13    >   IS_SMALLER                                               0, !0
         14      > JMPNZ                                                    ~15, ->6
   12    15    > > RETURN                                                   !3
   13    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/B38sS
function name:  gdr_decode
number of ops:  27
compiled vars:  !0 = $str, !1 = $chrs, !2 = $base, !3 = $map, !4 = $i, !5 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   17     1        ASSIGN                                                   !1, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+%21%23%24%25%26%27%28%29%2A%2B%2C-.%3A%3B%3C%3D%3E%3F%40%5B%5D%5E_%60%7B%7C%7D%7E'
   18     2        STRLEN                                           ~7      !1
          3        ASSIGN                                                   !2, ~7
   19     4        ASSIGN                                                   !3, <array>
   20     5        ASSIGN                                                   !4, 0
          6      > JMP                                                      ->11
   21     7    >   FETCH_DIM_R                                      ~11     !1, !4
          8        ASSIGN_DIM                                               !3, ~11
          9        OP_DATA                                                  !4
   20    10        PRE_INC                                                  !4
         11    >   IS_SMALLER                                               !4, !2
         12      > JMPNZ                                                    ~14, ->7
   23    13    >   ASSIGN                                                   !5, 0
   24    14        ASSIGN                                                   !4, 0
         15      > JMP                                                      ->22
   25    16    >   ASSIGN_OP                                     3          !5, !2
   26    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
   24    21        PRE_INC                                                  !4
         22    >   STRLEN                                           ~23     !0
         23        IS_SMALLER                                               !4, ~23
         24      > JMPNZ                                                    ~24, ->16
   28    25    > > RETURN                                                   !5
   29    26*     > RETURN                                                   null

End of function gdr_decode

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
183.21 ms | 1410 KiB | 17 Q