3v4l.org

run code in 500+ PHP versions simultaneously
<?php /** * Кодирует число в буквенно-числовую последовательность. * * @param int $number Число для кодирования. * @return string Закодированная буквенно-числовая последовательность. */ function encodeNumber(int $number): string { // Символы, используемые для кодирования $charset = join('', [...range('a', 'z'), ...range('A', 'Z'), ...range(0, 9)]); $base = strlen($charset); // Определение основания системы счисления $encoded = ''; // Преобразование числа в заданную систему счисления while ($number > 0) { $remainder = $number % $base; $encoded = $charset[$remainder] . $encoded; $number = (int) ($number / $base); } return $encoded; } /** * Декодирует буквенно-числовую последовательность в число. * * @param string $encoded Закодированная буквенно-числовая последовательность. * @return int Декодированное число. */ function decodeNumber(string $encoded): int { $charset = join('', [...range('a', 'z'), ...range('A', 'Z'), ...range(0, 9)]); $base = strlen($charset); $decoded = 0; // Преобразование буквенно-числовой последовательности в число $length = strlen($encoded); for ($i = 0; $i < $length; $i++) { $value = strpos($charset, $encoded[$i]); $decoded = $decoded * $base + $value; } return $decoded; } $numbers = [56789, 89567, 129087, 9999999, 1e8]; // Кодирование чисел и вывод закодированных значений foreach ($numbers as $number) { $encoded = encodeNumber($number); echo "$number: '$encoded' -> '" . decodeNumber($encoded) . "'\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 18
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 18
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/REX9l
function name:  (null)
number of ops:  20
compiled vars:  !0 = $numbers, !1 = $number, !2 = $encoded
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   46     0  E >   ASSIGN                                                       !0, <array>
   49     1      > FE_RESET_R                                           $4      !0, ->18
          2    > > FE_FETCH_R                                                   $4, !1, ->18
   50     3    >   INIT_FCALL                                                   'encodenumber'
          4        SEND_VAR                                                     !1
          5        DO_FCALL                                          0  $5      
          6        ASSIGN                                                       !2, $5
   51     7        ROPE_INIT                                         4  ~8      !1
          8        ROPE_ADD                                          1  ~8      ~8, '%3A+%27'
          9        ROPE_ADD                                          2  ~8      ~8, !2
         10        ROPE_END                                          3  ~7      ~8, '%27+-%3E+%27'
         11        INIT_FCALL                                                   'decodenumber'
         12        SEND_VAR                                                     !2
         13        DO_FCALL                                          0  $10     
         14        CONCAT                                               ~11     ~7, $10
         15        CONCAT                                               ~12     ~11, '%27%0A'
         16        ECHO                                                         ~12
   49    17      > JMP                                                          ->2
         18    >   FE_FREE                                                      $4
   52    19      > RETURN                                                       1

Function encodenumber:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 26
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 26
Branch analysis from position: 36
Branch analysis from position: 26
filename:       /in/REX9l
function name:  encodeNumber
number of ops:  40
compiled vars:  !0 = $number, !1 = $charset, !2 = $base, !3 = $encoded, !4 = $remainder
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    9     0  E >   RECV                                                 !0      
   11     1        INIT_FCALL                                                   'join'
          2        SEND_VAL                                                     ''
          3        INIT_FCALL                                                   'range'
          4        SEND_VAL                                                     'a'
          5        SEND_VAL                                                     'z'
          6        DO_ICALL                                             $5      
          7        INIT_ARRAY                                           ~6      
          8        ADD_ARRAY_UNPACK                                     ~6      $5
          9        INIT_FCALL                                                   'range'
         10        SEND_VAL                                                     'A'
         11        SEND_VAL                                                     'Z'
         12        DO_ICALL                                             $7      
         13        ADD_ARRAY_UNPACK                                     ~6      $7
         14        INIT_FCALL                                                   'range'
         15        SEND_VAL                                                     0
         16        SEND_VAL                                                     9
         17        DO_ICALL                                             $8      
         18        ADD_ARRAY_UNPACK                                     ~6      $8
         19        SEND_VAL                                                     ~6
         20        DO_ICALL                                             $9      
         21        ASSIGN                                                       !1, $9
   12    22        STRLEN                                               ~11     !1
         23        ASSIGN                                                       !2, ~11
   13    24        ASSIGN                                                       !3, ''
   16    25      > JMP                                                          ->34
   17    26    >   MOD                                                  ~14     !0, !2
         27        ASSIGN                                                       !4, ~14
   18    28        FETCH_DIM_R                                          ~16     !1, !4
         29        CONCAT                                               ~17     ~16, !3
         30        ASSIGN                                                       !3, ~17
   19    31        DIV                                                  ~19     !0, !2
         32        CAST                                              4  ~20     ~19
         33        ASSIGN                                                       !0, ~20
   16    34    >   IS_SMALLER                                                   0, !0
         35      > JMPNZ                                                        ~22, ->26
   22    36    >   VERIFY_RETURN_TYPE                                           !3
         37      > RETURN                                                       !3
   23    38*       VERIFY_RETURN_TYPE                                           
         39*     > RETURN                                                       null

End of function encodenumber

Function decodenumber:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 29
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 29
Branch analysis from position: 38
Branch analysis from position: 29
filename:       /in/REX9l
function name:  decodeNumber
number of ops:  42
compiled vars:  !0 = $encoded, !1 = $charset, !2 = $base, !3 = $decoded, !4 = $length, !5 = $i, !6 = $value
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   31     0  E >   RECV                                                 !0      
   32     1        INIT_FCALL                                                   'join'
          2        SEND_VAL                                                     ''
          3        INIT_FCALL                                                   'range'
          4        SEND_VAL                                                     'a'
          5        SEND_VAL                                                     'z'
          6        DO_ICALL                                             $7      
          7        INIT_ARRAY                                           ~8      
          8        ADD_ARRAY_UNPACK                                     ~8      $7
          9        INIT_FCALL                                                   'range'
         10        SEND_VAL                                                     'A'
         11        SEND_VAL                                                     'Z'
         12        DO_ICALL                                             $9      
         13        ADD_ARRAY_UNPACK                                     ~8      $9
         14        INIT_FCALL                                                   'range'
         15        SEND_VAL                                                     0
         16        SEND_VAL                                                     9
         17        DO_ICALL                                             $10     
         18        ADD_ARRAY_UNPACK                                     ~8      $10
         19        SEND_VAL                                                     ~8
         20        DO_ICALL                                             $11     
         21        ASSIGN                                                       !1, $11
   33    22        STRLEN                                               ~13     !1
         23        ASSIGN                                                       !2, ~13
   34    24        ASSIGN                                                       !3, 0
   37    25        STRLEN                                               ~16     !0
         26        ASSIGN                                                       !4, ~16
   38    27        ASSIGN                                                       !5, 0
         28      > JMP                                                          ->36
   39    29    >   FETCH_DIM_R                                          ~19     !0, !5
         30        FRAMELESS_ICALL_2                strpos              ~20     !1, ~19
         31        ASSIGN                                                       !6, ~20
   40    32        MUL                                                  ~22     !3, !2
         33        ADD                                                  ~23     ~22, !6
         34        ASSIGN                                                       !3, ~23
   38    35        PRE_INC                                                      !5
         36    >   IS_SMALLER                                                   !5, !4
         37      > JMPNZ                                                        ~26, ->29
   43    38    >   VERIFY_RETURN_TYPE                                           !3
         39      > RETURN                                                       !3
   44    40*       VERIFY_RETURN_TYPE                                           
         41*     > RETURN                                                       null

End of function decodenumber

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
158.37 ms | 1744 KiB | 17 Q