3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * BASE62 解析类,专门针对长mid与62进制互转,不适用其他操作 * * @copyright (c) 2009, 新浪网MiniBlog All rights reserved. * @author 王兆源 <zhaoyuan@staff.sina.com.cn> 朱建鑫 李如其 * @version 1.0 - 2009-08-05 * @package Tools */ class Base62Parse { private static $string = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; private static $encodeBlockSize = 7; private static $decodeBlockSize = 4; /** * 将mid转换成62进制字符串 * * @param string $mid * @return string */ function encode($mid) { $str = ""; $midlen = strlen($mid); $segments = ceil($midlen / self::$encodeBlockSize); $start = $midlen; for ( $i = 1; $i < $segments; $i+=1 ) { $start -= self::$encodeBlockSize; $seg = substr($mid, $start, self::$encodeBlockSize); $seg = self::encodeSegment($seg); $str = str_pad($seg, self::$decodeBlockSize, '0', STR_PAD_LEFT) . $str; } $str = self::encodeSegment(substr($mid, 0, $start)) . $str; return $str; } /** * 将62进制字符串转成10进制mid * * @param string $str * @return string */ function decode($str, $compat = false, $for_mid = true) { $mid = ""; $strlen = strlen($str); $segments = ceil($strlen / self::$decodeBlockSize); $start = $strlen; for ( $i = 1; $i < $segments; $i+=1 ) { $start -= self::$decodeBlockSize; $seg = substr($str, $start, self::$decodeBlockSize); $seg = self::decodeSegment($seg); $mid = str_pad($seg, self::$encodeBlockSize, '0', STR_PAD_LEFT) . $mid; } $mid = self::decodeSegment(substr($str, 0, $start)) . $mid; //判断v3版本mid if ( $for_mid && $mid > 4294967295 ) { if ( PHP_INT_SIZE < 8 ) { $cmd = "expr $mid / 4294967296"; $time = `$cmd`; } else { $mid += 0; $time = $mid >> 32; //64位中前32位是时间,精确到秒级 } if ( $time > 1230739200 && $time < 1577808000 ) return $mid; } //end if ( $compat && !in_array(substr($mid, 0, 3), array('109', '110', '201', '211', '221', '231', '241')) ) { $mid = self::decodeSegment(substr($str, 0, 4)) . self::decodeSegment(substr($str, 4)); } if ( $for_mid ) { if ( substr($mid, 0, 1) == '1' && substr($mid, 7, 1) == '0' ) { $mid = substr($mid, 0, 7) . substr($mid, 8); } } return $mid; } /** * 将10进制转换成62进制 * * @param string $str 10进制字符串 * @return string */ function encodeSegment($str) { $out = ''; while ( $str > 0 ) { $idx = $str % 62; $out = substr(self::$string, $idx, 1) . $out; $str = floor($str / 62); } return $out; } /** * 将62进制转换成10进制 * * @param string $str 62进制字符串 * @return string */ function decodeSegment($str) { $out = 0; $base = 1; for ( $t = strlen($str) - 1; $t >= 0; $t-=1 ) { $out = $out + $base * strpos(self::$string, substr($str, $t, 1)); $base *= 62; } return $out . ""; } } var_dump(Base62Parse::decode('yvab0DLBV'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8I6iH
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  119     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_STATIC_METHOD_CALL                                  'Base62Parse', 'decode'
          2        SEND_VAL                                                 'yvab0DLBV'
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
          6      > RETURN                                                   1

Class Base62Parse:
Function encode:
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 = 13
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 13
Branch analysis from position: 38
Branch analysis from position: 13
filename:       /in/8I6iH
function name:  encode
number of ops:  50
compiled vars:  !0 = $mid, !1 = $str, !2 = $midlen, !3 = $segments, !4 = $start, !5 = $i, !6 = $seg
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   25     1        ASSIGN                                                   !1, ''
   26     2        STRLEN                                           ~8      !0
          3        ASSIGN                                                   !2, ~8
   27     4        INIT_FCALL                                               'ceil'
          5        FETCH_STATIC_PROP_R          global lock         ~10     'encodeBlockSize'
          6        DIV                                              ~11     !2, ~10
          7        SEND_VAL                                                 ~11
          8        DO_ICALL                                         $12     
          9        ASSIGN                                                   !3, $12
   28    10        ASSIGN                                                   !4, !2
   29    11        ASSIGN                                                   !5, 1
         12      > JMP                                                      ->36
   31    13    >   FETCH_STATIC_PROP_R          unknown             ~16     'encodeBlockSize'
         14        ASSIGN_OP                                     2          !4, ~16
   32    15        INIT_FCALL                                               'substr'
         16        SEND_VAR                                                 !0
         17        SEND_VAR                                                 !4
         18        FETCH_STATIC_PROP_R          unknown             ~18     'encodeBlockSize'
         19        SEND_VAL                                                 ~18
         20        DO_ICALL                                         $19     
         21        ASSIGN                                                   !6, $19
   33    22        INIT_STATIC_METHOD_CALL                                  'encodeSegment'
         23        SEND_VAR_EX                                              !6
         24        DO_FCALL                                      0  $21     
         25        ASSIGN                                                   !6, $21
   34    26        INIT_FCALL                                               'str_pad'
         27        SEND_VAR                                                 !6
         28        FETCH_STATIC_PROP_R          unknown             ~23     'decodeBlockSize'
         29        SEND_VAL                                                 ~23
         30        SEND_VAL                                                 '0'
         31        SEND_VAL                                                 0
         32        DO_ICALL                                         $24     
         33        CONCAT                                           ~25     $24, !1
         34        ASSIGN                                                   !1, ~25
   29    35        ASSIGN_OP                                     1          !5, 1
         36    >   IS_SMALLER                                               !5, !3
         37      > JMPNZ                                                    ~28, ->13
   36    38    >   INIT_STATIC_METHOD_CALL                                  'encodeSegment'
         39        INIT_FCALL                                               'substr'
         40        SEND_VAR                                                 !0
         41        SEND_VAL                                                 0
         42        SEND_VAR                                                 !4
         43        DO_ICALL                                         $29     
         44        SEND_VAR_NO_REF_EX                                       $29
         45        DO_FCALL                                      0  $30     
         46        CONCAT                                           ~31     $30, !1
         47        ASSIGN                                                   !1, ~31
   37    48      > RETURN                                                   !1
   38    49*     > RETURN                                                   null

End of function encode

Function decode:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 15
Branch analysis from position: 40
2 jumps found. (Code = 46) Position 1 = 51, Position 2 = 53
Branch analysis from position: 51
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 74
Branch analysis from position: 54
2 jumps found. (Code = 43) Position 1 = 55, Position 2 = 65
Branch analysis from position: 55
1 jumps found. (Code = 42) Position 1 = 68
Branch analysis from position: 68
2 jumps found. (Code = 46) Position 1 = 70, Position 2 = 72
Branch analysis from position: 70
2 jumps found. (Code = 43) Position 1 = 73, Position 2 = 74
Branch analysis from position: 73
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 74
2 jumps found. (Code = 46) Position 1 = 75, Position 2 = 86
Branch analysis from position: 75
2 jumps found. (Code = 43) Position 1 = 87, Position 2 = 104
Branch analysis from position: 87
2 jumps found. (Code = 43) Position 1 = 105, Position 2 = 131
Branch analysis from position: 105
2 jumps found. (Code = 46) Position 1 = 112, Position 2 = 119
Branch analysis from position: 112
2 jumps found. (Code = 43) Position 1 = 120, Position 2 = 131
Branch analysis from position: 120
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 131
Branch analysis from position: 119
Branch analysis from position: 131
Branch analysis from position: 104
Branch analysis from position: 86
Branch analysis from position: 72
Branch analysis from position: 65
2 jumps found. (Code = 46) Position 1 = 70, Position 2 = 72
Branch analysis from position: 70
Branch analysis from position: 72
Branch analysis from position: 74
Branch analysis from position: 53
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 15
Branch analysis from position: 40
Branch analysis from position: 15
filename:       /in/8I6iH
function name:  decode
number of ops:  133
compiled vars:  !0 = $str, !1 = $compat, !2 = $for_mid, !3 = $mid, !4 = $strlen, !5 = $segments, !6 = $start, !7 = $i, !8 = $seg, !9 = $cmd, !10 = $time
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <false>
          2        RECV_INIT                                        !2      <true>
   48     3        ASSIGN                                                   !3, ''
   49     4        STRLEN                                           ~12     !0
          5        ASSIGN                                                   !4, ~12
   50     6        INIT_FCALL                                               'ceil'
          7        FETCH_STATIC_PROP_R          global lock         ~14     'decodeBlockSize'
          8        DIV                                              ~15     !4, ~14
          9        SEND_VAL                                                 ~15
         10        DO_ICALL                                         $16     
         11        ASSIGN                                                   !5, $16
   51    12        ASSIGN                                                   !6, !4
   52    13        ASSIGN                                                   !7, 1
         14      > JMP                                                      ->38
   54    15    >   FETCH_STATIC_PROP_R          unknown             ~20     'decodeBlockSize'
         16        ASSIGN_OP                                     2          !6, ~20
   55    17        INIT_FCALL                                               'substr'
         18        SEND_VAR                                                 !0
         19        SEND_VAR                                                 !6
         20        FETCH_STATIC_PROP_R          unknown             ~22     'decodeBlockSize'
         21        SEND_VAL                                                 ~22
         22        DO_ICALL                                         $23     
         23        ASSIGN                                                   !8, $23
   56    24        INIT_STATIC_METHOD_CALL                                  'decodeSegment'
         25        SEND_VAR_EX                                              !8
         26        DO_FCALL                                      0  $25     
         27        ASSIGN                                                   !8, $25
   57    28        INIT_FCALL                                               'str_pad'
         29        SEND_VAR                                                 !8
         30        FETCH_STATIC_PROP_R          unknown             ~27     'encodeBlockSize'
         31        SEND_VAL                                                 ~27
         32        SEND_VAL                                                 '0'
         33        SEND_VAL                                                 0
         34        DO_ICALL                                         $28     
         35        CONCAT                                           ~29     $28, !3
         36        ASSIGN                                                   !3, ~29
   52    37        ASSIGN_OP                                     1          !7, 1
         38    >   IS_SMALLER                                               !7, !5
         39      > JMPNZ                                                    ~32, ->15
   59    40    >   INIT_STATIC_METHOD_CALL                                  'decodeSegment'
         41        INIT_FCALL                                               'substr'
         42        SEND_VAR                                                 !0
         43        SEND_VAL                                                 0
         44        SEND_VAR                                                 !6
         45        DO_ICALL                                         $33     
         46        SEND_VAR_NO_REF_EX                                       $33
         47        DO_FCALL                                      0  $34     
         48        CONCAT                                           ~35     $34, !3
         49        ASSIGN                                                   !3, ~35
   61    50      > JMPZ_EX                                          ~37     !2, ->53
         51    >   IS_SMALLER                                       ~38     4294967295, !3
         52        BOOL                                             ~37     ~38
         53    > > JMPZ                                                     ~37, ->74
   62    54    > > JMPZ                                                     <false>, ->65
   63    55    >   ROPE_INIT                                     3  ~40     'expr+'
         56        ROPE_ADD                                      1  ~40     ~40, !3
         57        ROPE_END                                      2  ~39     ~40, '+%2F+4294967296'
         58        ASSIGN                                                   !9, ~39
   64    59        INIT_FCALL                                               'shell_exec'
         60        CAST                                          6  ~43     !9
         61        SEND_VAL                                                 ~43
         62        DO_ICALL                                         $44     
         63        ASSIGN                                                   !10, $44
         64      > JMP                                                      ->68
   66    65    >   ASSIGN_OP                                     1          !3, 0
   67    66        SR                                               ~47     !3, 32
         67        ASSIGN                                                   !10, ~47
   69    68    >   IS_SMALLER                                       ~49     1230739200, !10
         69      > JMPZ_EX                                          ~49     ~49, ->72
         70    >   IS_SMALLER                                       ~50     !10, 1577808000
         71        BOOL                                             ~49     ~50
         72    > > JMPZ                                                     ~49, ->74
         73    > > RETURN                                                   !3
   72    74    > > JMPZ_EX                                          ~51     !1, ->86
         75    >   INIT_FCALL                                               'in_array'
         76        INIT_FCALL                                               'substr'
         77        SEND_VAR                                                 !3
         78        SEND_VAL                                                 0
         79        SEND_VAL                                                 3
         80        DO_ICALL                                         $52     
         81        SEND_VAR                                                 $52
         82        SEND_VAL                                                 <array>
         83        DO_ICALL                                         $53     
         84        BOOL_NOT                                         ~54     $53
         85        BOOL                                             ~51     ~54
         86    > > JMPZ                                                     ~51, ->104
   73    87    >   INIT_STATIC_METHOD_CALL                                  'decodeSegment'
         88        INIT_FCALL                                               'substr'
         89        SEND_VAR                                                 !0
         90        SEND_VAL                                                 0
         91        SEND_VAL                                                 4
         92        DO_ICALL                                         $55     
         93        SEND_VAR_NO_REF_EX                                       $55
         94        DO_FCALL                                      0  $56     
         95        INIT_STATIC_METHOD_CALL                                  'decodeSegment'
         96        INIT_FCALL                                               'substr'
         97        SEND_VAR                                                 !0
         98        SEND_VAL                                                 4
         99        DO_ICALL                                         $57     
        100        SEND_VAR_NO_REF_EX                                       $57
        101        DO_FCALL                                      0  $58     
        102        CONCAT                                           ~59     $56, $58
        103        ASSIGN                                                   !3, ~59
   75   104    > > JMPZ                                                     !2, ->131
   76   105    >   INIT_FCALL                                               'substr'
        106        SEND_VAR                                                 !3
        107        SEND_VAL                                                 0
        108        SEND_VAL                                                 1
        109        DO_ICALL                                         $61     
        110        IS_EQUAL                                         ~62     $61, '1'
        111      > JMPZ_EX                                          ~62     ~62, ->119
        112    >   INIT_FCALL                                               'substr'
        113        SEND_VAR                                                 !3
        114        SEND_VAL                                                 7
        115        SEND_VAL                                                 1
        116        DO_ICALL                                         $63     
        117        IS_EQUAL                                         ~64     $63, '0'
        118        BOOL                                             ~62     ~64
        119    > > JMPZ                                                     ~62, ->131
   77   120    >   INIT_FCALL                                               'substr'
        121        SEND_VAR                                                 !3
        122        SEND_VAL                                                 0
        123        SEND_VAL                                                 7
        124        DO_ICALL                                         $65     
        125        INIT_FCALL                                               'substr'
        126        SEND_VAR                                                 !3
        127        SEND_VAL                                                 8
        128        DO_ICALL                                         $66     
        129        CONCAT                                           ~67     $65, $66
        130        ASSIGN                                                   !3, ~67
   80   131    > > RETURN                                                   !3
   81   132*     > RETURN                                                   null

End of function decode

Function encodesegment:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 3
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 3
Branch analysis from position: 20
Branch analysis from position: 3
filename:       /in/8I6iH
function name:  encodeSegment
number of ops:  22
compiled vars:  !0 = $str, !1 = $out, !2 = $idx
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   89     0  E >   RECV                                             !0      
   91     1        ASSIGN                                                   !1, ''
   92     2      > JMP                                                      ->18
   93     3    >   MOD                                              ~4      !0, 62
          4        ASSIGN                                                   !2, ~4
   94     5        INIT_FCALL                                               'substr'
          6        FETCH_STATIC_PROP_R          global lock         ~6      'string'
          7        SEND_VAL                                                 ~6
          8        SEND_VAR                                                 !2
          9        SEND_VAL                                                 1
         10        DO_ICALL                                         $7      
         11        CONCAT                                           ~8      $7, !1
         12        ASSIGN                                                   !1, ~8
   95    13        INIT_FCALL                                               'floor'
         14        DIV                                              ~10     !0, 62
         15        SEND_VAL                                                 ~10
         16        DO_ICALL                                         $11     
         17        ASSIGN                                                   !0, $11
   92    18    >   IS_SMALLER                                               0, !0
         19      > JMPNZ                                                    ~13, ->3
   97    20    > > RETURN                                                   !1
   98    21*     > RETURN                                                   null

End of function encodesegment

Function decodesegment:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 7
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 7
Branch analysis from position: 24
Branch analysis from position: 7
filename:       /in/8I6iH
function name:  decodeSegment
number of ops:  27
compiled vars:  !0 = $str, !1 = $out, !2 = $base, !3 = $t
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  106     0  E >   RECV                                             !0      
  108     1        ASSIGN                                                   !1, 0
  109     2        ASSIGN                                                   !2, 1
  110     3        STRLEN                                           ~6      !0
          4        SUB                                              ~7      ~6, 1
          5        ASSIGN                                                   !3, ~7
          6      > JMP                                                      ->22
  112     7    >   INIT_FCALL                                               'strpos'
          8        FETCH_STATIC_PROP_R          global lock         ~9      'string'
          9        SEND_VAL                                                 ~9
         10        INIT_FCALL                                               'substr'
         11        SEND_VAR                                                 !0
         12        SEND_VAR                                                 !3
         13        SEND_VAL                                                 1
         14        DO_ICALL                                         $10     
         15        SEND_VAR                                                 $10
         16        DO_ICALL                                         $11     
         17        MUL                                              ~12     !2, $11
         18        ADD                                              ~13     !1, ~12
         19        ASSIGN                                                   !1, ~13
  113    20        ASSIGN_OP                                     3          !2, 62
  110    21        ASSIGN_OP                                     2          !3, 1
         22    >   IS_SMALLER_OR_EQUAL                                      0, !3
         23      > JMPNZ                                                    ~17, ->7
  115    24    >   CONCAT                                           ~18     !1, ''
         25      > RETURN                                                   ~18
  116    26*     > RETURN                                                   null

End of function decodesegment

End of class Base62Parse.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.45 ms | 1420 KiB | 29 Q