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; } echo gdr_decode('~~~') . "\n\n"; function duration($val) { if ($val < 24) { return sprintf('%d', $val).'h'; } if ($val < 24*10) { return sprintf('%1.1f', $val/24).'d'; } if ($val < 168*10) { return sprintf('%1.1f', $val/168).'w'; } //if ($val < 730*10) { // return sprintf('%1.1f', $val/730).'m'; //} return sprintf('%1.1f', $val/8760).'y'; } $vals = array( 0, 1, 99, 100, 255, 256, 999, 1000, 9999, 10000, 65535, 65536, 99999, 100000, 250000, 500000, 750000, 999999, 1000000, 9999999, //4294967295, 4294967296 ); echo sprintf("%7s %7s %7s %4s\n", 'num', 'str', 'time', 'cmp'); foreach ($vals as $val) { $enc = gdr_encode($val); $dec = gdr_decode($enc); if ($dec !== $val) { echo "ERROR: $val => $enc => $dec\n"; } else { echo sprintf("%7d %7s %7s %4d\n", $dec, "\"$enc\"", duration($val), strlen($enc)+2-strlen($val)); } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 54
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 54
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 35
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 54
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 54
filename:       /in/7gQpZ
function name:  (null)
number of ops:  56
compiled vars:  !0 = $vals, !1 = $val, !2 = $enc, !3 = $dec
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   INIT_FCALL                                               'gdr_decode'
          1        SEND_VAL                                                 '%7E%7E%7E'
          2        DO_FCALL                                      0  $4      
          3        CONCAT                                           ~5      $4, '%0A%0A'
          4        ECHO                                                     ~5
   49     5        ASSIGN                                                   !0, <array>
   53     6        INIT_FCALL                                               'sprintf'
          7        SEND_VAL                                                 '%257s+%257s+%257s+%254s%0A'
          8        SEND_VAL                                                 'num'
          9        SEND_VAL                                                 'str'
         10        SEND_VAL                                                 'time'
         11        SEND_VAL                                                 'cmp'
         12        DO_ICALL                                         $7      
         13        ECHO                                                     $7
   54    14      > FE_RESET_R                                       $8      !0, ->54
         15    > > FE_FETCH_R                                               $8, !1, ->54
   55    16    >   INIT_FCALL                                               'gdr_encode'
         17        SEND_VAR                                                 !1
         18        DO_FCALL                                      0  $9      
         19        ASSIGN                                                   !2, $9
   56    20        INIT_FCALL                                               'gdr_decode'
         21        SEND_VAR                                                 !2
         22        DO_FCALL                                      0  $11     
         23        ASSIGN                                                   !3, $11
   57    24        IS_NOT_IDENTICAL                                         !3, !1
         25      > JMPZ                                                     ~13, ->35
   58    26    >   ROPE_INIT                                     7  ~15     'ERROR%3A+'
         27        ROPE_ADD                                      1  ~15     ~15, !1
         28        ROPE_ADD                                      2  ~15     ~15, '+%3D%3E+'
         29        ROPE_ADD                                      3  ~15     ~15, !2
         30        ROPE_ADD                                      4  ~15     ~15, '+%3D%3E+'
         31        ROPE_ADD                                      5  ~15     ~15, !3
         32        ROPE_END                                      6  ~14     ~15, '%0A'
         33        ECHO                                                     ~14
         34      > JMP                                                      ->53
   60    35    >   INIT_FCALL                                               'sprintf'
         36        SEND_VAL                                                 '%257d+%257s+%257s+%254d%0A'
         37        SEND_VAR                                                 !3
         38        ROPE_INIT                                     3  ~20     '%22'
         39        ROPE_ADD                                      1  ~20     ~20, !2
         40        ROPE_END                                      2  ~19     ~20, '%22'
         41        SEND_VAL                                                 ~19
         42        INIT_FCALL                                               'duration'
         43        SEND_VAR                                                 !1
         44        DO_FCALL                                      0  $22     
         45        SEND_VAR                                                 $22
         46        STRLEN                                           ~23     !2
         47        ADD                                              ~24     ~23, 2
         48        STRLEN                                           ~25     !1
         49        SUB                                              ~26     ~24, ~25
         50        SEND_VAL                                                 ~26
         51        DO_ICALL                                         $27     
         52        ECHO                                                     $27
   54    53    > > JMP                                                      ->15
         54    >   FE_FREE                                                  $8
   62    55      > 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/7gQpZ
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/7gQpZ
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

Function duration:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 18
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 27
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7gQpZ
function name:  duration
number of ops:  35
compiled vars:  !0 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
   34     1        IS_SMALLER                                               !0, 24
          2      > JMPZ                                                     ~1, ->9
   35     3    >   INIT_FCALL                                               'sprintf'
          4        SEND_VAL                                                 '%25d'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $2      
          7        CONCAT                                           ~3      $2, 'h'
          8      > RETURN                                                   ~3
   37     9    >   IS_SMALLER                                               !0, 240
         10      > JMPZ                                                     ~4, ->18
   38    11    >   INIT_FCALL                                               'sprintf'
         12        SEND_VAL                                                 '%251.1f'
         13        DIV                                              ~5      !0, 24
         14        SEND_VAL                                                 ~5
         15        DO_ICALL                                         $6      
         16        CONCAT                                           ~7      $6, 'd'
         17      > RETURN                                                   ~7
   40    18    >   IS_SMALLER                                               !0, 1680
         19      > JMPZ                                                     ~8, ->27
   41    20    >   INIT_FCALL                                               'sprintf'
         21        SEND_VAL                                                 '%251.1f'
         22        DIV                                              ~9      !0, 168
         23        SEND_VAL                                                 ~9
         24        DO_ICALL                                         $10     
         25        CONCAT                                           ~11     $10, 'w'
         26      > RETURN                                                   ~11
   46    27    >   INIT_FCALL                                               'sprintf'
         28        SEND_VAL                                                 '%251.1f'
         29        DIV                                              ~12     !0, 8760
         30        SEND_VAL                                                 ~12
         31        DO_ICALL                                         $13     
         32        CONCAT                                           ~14     $13, 'y'
         33      > RETURN                                                   ~14
   47    34*     > RETURN                                                   null

End of function duration

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.18 ms | 1402 KiB | 19 Q