3v4l.org

run code in 300+ PHP versions simultaneously
<?php function msubstr($str, $start=0, $length, $charset="utf-8", $suffix=true) { if($suffix) $suffixStr = "…"; else $suffixStr = ""; if(function_exists("mb_substr")) return mb_substr($str, $start, $length, $charset).$suffixStr; elseif(function_exists('iconv_substr')) { return iconv_substr($str,$start,$length,$charset).$suffixStr; } $re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/"; $re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/"; $re['gbk'] = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/"; $re['big5'] = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/"; preg_match_all($re[$charset], $str, $match); $slice = join("",array_slice($match[0], $start, $length)); return $slice.$suffixStr; } function csubstr($str, $start=0, $length, $charset="utf-8", $suffix=true) { if(function_exists("mb_substr")) return mb_substr($str, $start, $length, $charset); $re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/"; $re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/"; $re['gbk'] = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/"; $re['big5'] = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/"; preg_match_all($re[$charset], $str, $match); $slice = join("",array_slice($match[0], $start, $length)); if($suffix) return $slice."…"; return $slice; } $a = '测试这是一个测试'; //$a = 'xxxxbbbbbnnn'; $b = csubstr($a,0,5); var_dump($b); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/O7B22
function name:  (null)
number of ops:  11
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   ASSIGN                                                   !0, '%E6%B5%8B%E8%AF%95%E8%BF%99%E6%98%AF%E4%B8%80%E4%B8%AA%E6%B5%8B%E8%AF%95'
   41     1        INIT_FCALL                                               'csubstr'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 0
          4        SEND_VAL                                                 5
          5        DO_FCALL                                      0  $3      
          6        ASSIGN                                                   !1, $3
   42     7        INIT_FCALL                                               'var_dump'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                                 
   44    10      > RETURN                                                   1

Function msubstr:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 22
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 34
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 22
Branch analysis from position: 13
Branch analysis from position: 22
filename:       /in/O7B22
function name:  msubstr
number of ops:  62
compiled vars:  !0 = $str, !1 = $start, !2 = $length, !3 = $charset, !4 = $suffix, !5 = $suffixStr, !6 = $re, !7 = $match, !8 = $slice
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
          2        RECV                                             !2      
          3        RECV_INIT                                        !3      'utf-8'
          4        RECV_INIT                                        !4      <true>
    5     5      > JMPZ                                                     !4, ->8
    6     6    >   ASSIGN                                                   !5, '%E2%80%A6'
          7      > JMP                                                      ->9
    8     8    >   ASSIGN                                                   !5, ''
   10     9    >   INIT_FCALL                                               'function_exists'
         10        SEND_VAL                                                 'mb_substr'
         11        DO_ICALL                                         $11     
         12      > JMPZ                                                     $11, ->22
   11    13    >   INIT_FCALL                                               'mb_substr'
         14        SEND_VAR                                                 !0
         15        SEND_VAR                                                 !1
         16        SEND_VAR                                                 !2
         17        SEND_VAR                                                 !3
         18        DO_ICALL                                         $12     
         19        CONCAT                                           ~13     $12, !5
         20      > RETURN                                                   ~13
         21*       JMP                                                      ->34
   12    22    >   INIT_FCALL                                               'function_exists'
         23        SEND_VAL                                                 'iconv_substr'
         24        DO_ICALL                                         $14     
         25      > JMPZ                                                     $14, ->34
   13    26    >   INIT_FCALL_BY_NAME                                       'iconv_substr'
         27        SEND_VAR_EX                                              !0
         28        SEND_VAR_EX                                              !1
         29        SEND_VAR_EX                                              !2
         30        SEND_VAR_EX                                              !3
         31        DO_FCALL                                      0  $15     
         32        CONCAT                                           ~16     $15, !5
         33      > RETURN                                                   ~16
   15    34    >   ASSIGN_DIM                                               !6, 'utf-8'
         35        OP_DATA                                                  '%2F%5B%01-%7F%5D%7C%5B%C2-%DF%5D%5B%80-%BF%5D%7C%5B%E0-%EF%5D%5B%80-%BF%5D%7B2%7D%7C%5B%F0-%FF%5D%5B%80-%BF%5D%7B3%7D%2F'
   16    36        ASSIGN_DIM                                               !6, 'gb2312'
         37        OP_DATA                                                  '%2F%5B%01-%7F%5D%7C%5B%B0-%F7%5D%5B%A0-%FE%5D%2F'
   17    38        ASSIGN_DIM                                               !6, 'gbk'
         39        OP_DATA                                                  '%2F%5B%01-%7F%5D%7C%5B%81-%FE%5D%5B%40-%FE%5D%2F'
   18    40        ASSIGN_DIM                                               !6, 'big5'
         41        OP_DATA                                                  '%2F%5B%01-%7F%5D%7C%5B%81-%FE%5D%28%5B%40-%7E%5D%7C%A1-%FE%5D%29%2F'
   19    42        INIT_FCALL                                               'preg_match_all'
         43        FETCH_DIM_R                                      ~21     !6, !3
         44        SEND_VAL                                                 ~21
         45        SEND_VAR                                                 !0
         46        SEND_REF                                                 !7
         47        DO_ICALL                                                 
   20    48        INIT_FCALL                                               'join'
         49        SEND_VAL                                                 ''
         50        INIT_FCALL                                               'array_slice'
         51        FETCH_DIM_R                                      ~23     !7, 0
         52        SEND_VAL                                                 ~23
         53        SEND_VAR                                                 !1
         54        SEND_VAR                                                 !2
         55        DO_ICALL                                         $24     
         56        SEND_VAR                                                 $24
         57        DO_ICALL                                         $25     
         58        ASSIGN                                                   !8, $25
   21    59        CONCAT                                           ~27     !8, !5
         60      > RETURN                                                   ~27
   22    61*     > RETURN                                                   null

End of function msubstr

Function csubstr:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 16
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 44
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/O7B22
function name:  csubstr
number of ops:  46
compiled vars:  !0 = $str, !1 = $start, !2 = $length, !3 = $charset, !4 = $suffix, !5 = $re, !6 = $match, !7 = $slice
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
          2        RECV                                             !2      
          3        RECV_INIT                                        !3      'utf-8'
          4        RECV_INIT                                        !4      <true>
   26     5        INIT_FCALL                                               'function_exists'
          6        SEND_VAL                                                 'mb_substr'
          7        DO_ICALL                                         $8      
          8      > JMPZ                                                     $8, ->16
   27     9    >   INIT_FCALL                                               'mb_substr'
         10        SEND_VAR                                                 !0
         11        SEND_VAR                                                 !1
         12        SEND_VAR                                                 !2
         13        SEND_VAR                                                 !3
         14        DO_ICALL                                         $9      
         15      > RETURN                                                   $9
   28    16    >   ASSIGN_DIM                                               !5, 'utf-8'
         17        OP_DATA                                                  '%2F%5B%01-%7F%5D%7C%5B%C2-%DF%5D%5B%80-%BF%5D%7C%5B%E0-%EF%5D%5B%80-%BF%5D%7B2%7D%7C%5B%F0-%FF%5D%5B%80-%BF%5D%7B3%7D%2F'
   29    18        ASSIGN_DIM                                               !5, 'gb2312'
         19        OP_DATA                                                  '%2F%5B%01-%7F%5D%7C%5B%B0-%F7%5D%5B%A0-%FE%5D%2F'
   30    20        ASSIGN_DIM                                               !5, 'gbk'
         21        OP_DATA                                                  '%2F%5B%01-%7F%5D%7C%5B%81-%FE%5D%5B%40-%FE%5D%2F'
   31    22        ASSIGN_DIM                                               !5, 'big5'
         23        OP_DATA                                                  '%2F%5B%01-%7F%5D%7C%5B%81-%FE%5D%28%5B%40-%7E%5D%7C%A1-%FE%5D%29%2F'
   32    24        INIT_FCALL                                               'preg_match_all'
         25        FETCH_DIM_R                                      ~14     !5, !3
         26        SEND_VAL                                                 ~14
         27        SEND_VAR                                                 !0
         28        SEND_REF                                                 !6
         29        DO_ICALL                                                 
   33    30        INIT_FCALL                                               'join'
         31        SEND_VAL                                                 ''
         32        INIT_FCALL                                               'array_slice'
         33        FETCH_DIM_R                                      ~16     !6, 0
         34        SEND_VAL                                                 ~16
         35        SEND_VAR                                                 !1
         36        SEND_VAR                                                 !2
         37        DO_ICALL                                         $17     
         38        SEND_VAR                                                 $17
         39        DO_ICALL                                         $18     
         40        ASSIGN                                                   !7, $18
   34    41      > JMPZ                                                     !4, ->44
         42    >   CONCAT                                           ~20     !7, '%E2%80%A6'
         43      > RETURN                                                   ~20
   35    44    > > RETURN                                                   !7
   36    45*     > RETURN                                                   null

End of function csubstr

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.23 ms | 1411 KiB | 26 Q