3v4l.org

run code in 300+ PHP versions simultaneously
<?php function cn_substr_utf8($str, $length, $start=0) { 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]; } else { break; } } } return $str; } $a = '测试这是一个测试'; //$a = 'xxxxbbbbbnnn'; $b = cn_substr_utf8($a,5,0); var_dump($b); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AK25R
function name:  (null)
number of ops:  11
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     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'
   38     1        INIT_FCALL                                               'cn_substr_utf8'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 5
          4        SEND_VAL                                                 0
          5        DO_FCALL                                      0  $3      
          6        ASSIGN                                                   !1, $3
   39     7        INIT_FCALL                                               'var_dump'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                                 
   41    10      > 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 = 37
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 17
Branch analysis from position: 40
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 = 36
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 17
Branch analysis from position: 40
Branch analysis from position: 17
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 35
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
filename:       /in/AK25R
function name:  cn_substr_utf8
number of ops:  42
compiled vars:  !0 = $str, !1 = $length, !2 = $start, !3 = $ar, !4 = $tstr, !5 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      0
    5     3        STRLEN                                           ~6      !0
          4        ADD                                              ~7      !2, 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                                                      ->37
   15    17    >   STRLEN                                           ~13     !4
         18        IS_SMALLER                                               ~13, !2
         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                                                      ->36
   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     !1, ~21
         29        IS_SMALLER                                               ~18, ~22
         30      > JMPZ                                                     ~23, ->35
   23    31    >   FETCH_DIM_R                                      ~24     !3, 0
         32        FETCH_DIM_R                                      ~25     ~24, !5
         33        ASSIGN_OP                                     8          !0, ~25
         34      > JMP                                                      ->36
   27    35    > > JMP                                                      ->40
   13    36    >   PRE_INC                                                  !5
         37    >   FETCH_DIM_IS                                     ~28     !3, 0
         38        ISSET_ISEMPTY_DIM_OBJ                         0          ~28, !5
         39      > JMPNZ                                                    ~29, ->17
   31    40    > > RETURN                                                   !0
   32    41*     > RETURN                                                   null

End of function cn_substr_utf8

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.76 ms | 1394 KiB | 18 Q