3v4l.org

run code in 300+ PHP versions simultaneously
<?php function cn_substr_utf8($str, $start=0,$length) { if(strlen($str) < $start+1) { return ''; } preg_match_all("/./su", $str, $ar); $str = ''; $tstr = ''; //为了兼容mysql教程4.1以下版本,与数据库教程varchar一致,这里使用按字节截取 for($i=0; isset($ar[0][$i]); $i++) { if(strlen($tstr) < $start) { $tstr .= $ar[0][$i]; } else { if(strlen($str) < $length + strlen($ar[0][$i]) ) { $str .= $ar[0][$i-1]; } else { break; } } } return $str; } $a = '测试这是一个测试'; $a = 'xxxxbbbbbnnn'; $b = cn_substr_utf8($a,0,6,'utf-8'); var_dump($b); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Sc91D
function name:  (null)
number of ops:  13
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     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'
   37     1        ASSIGN                                                   !0, 'xxxxbbbbbnnn'
   39     2        INIT_FCALL                                               'cn_substr_utf8'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 0
          5        SEND_VAL                                                 6
          6        SEND_VAL                                                 'utf-8'
          7        DO_FCALL                                      0  $4      
          8        ASSIGN                                                   !1, $4
   40     9        INIT_FCALL                                               'var_dump'
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                                 
   42    12      > RETURN                                                   1

Function cn_substr_utf8:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 17
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 24
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 17
Branch analysis from position: 41
Branch analysis from position: 17
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 36
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
filename:       /in/Sc91D
function name:  cn_substr_utf8
number of ops:  43
compiled vars:  !0 = $str, !1 = $start, !2 = $length, !3 = $ar, !4 = $tstr, !5 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
          2        RECV                                             !2      
    5     3        STRLEN                                           ~6      !0
          4        ADD                                              ~7      !1, 1
          5        IS_SMALLER                                               ~6, ~7
          6      > JMPZ                                                     ~8, ->8
    7     7    > > RETURN                                                   ''
    9     8    >   INIT_FCALL                                               'preg_match_all'
          9        SEND_VAL                                                 '%2F.%2Fsu'
         10        SEND_VAR                                                 !0
         11        SEND_REF                                                 !3
         12        DO_ICALL                                                 
   10    13        ASSIGN                                                   !0, ''
   11    14        ASSIGN                                                   !4, ''
   13    15        ASSIGN                                                   !5, 0
         16      > JMP                                                      ->38
   15    17    >   STRLEN                                           ~13     !4
         18        IS_SMALLER                                               ~13, !1
         19      > JMPZ                                                     ~14, ->24
   17    20    >   FETCH_DIM_R                                      ~15     !3, 0
         21        FETCH_DIM_R                                      ~16     ~15, !5
         22        ASSIGN_OP                                     8          !4, ~16
         23      > JMP                                                      ->37
   21    24    >   STRLEN                                           ~18     !0
         25        FETCH_DIM_R                                      ~19     !3, 0
         26        FETCH_DIM_R                                      ~20     ~19, !5
         27        STRLEN                                           ~21     ~20
         28        ADD                                              ~22     !2, ~21
         29        IS_SMALLER                                               ~18, ~22
         30      > JMPZ                                                     ~23, ->36
   23    31    >   SUB                                              ~25     !5, 1
         32        FETCH_DIM_R                                      ~24     !3, 0
         33        FETCH_DIM_R                                      ~26     ~24, ~25
         34        ASSIGN_OP                                     8          !0, ~26
         35      > JMP                                                      ->37
   27    36    > > JMP                                                      ->41
   13    37    >   PRE_INC                                                  !5
         38    >   FETCH_DIM_IS                                     ~29     !3, 0
         39        ISSET_ISEMPTY_DIM_OBJ                         0          ~29, !5
         40      > JMPNZ                                                    ~30, ->17
   31    41    > > RETURN                                                   !0
   32    42*     > RETURN                                                   null

End of function cn_substr_utf8

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.16 ms | 1394 KiB | 18 Q