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); var_dump($ar); $str = ''; $tstr = ''; //为了兼容mysql教程4.1以下版本,与数据库教程varchar一致,这里使用按字节截取 for($i=1; 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; } } } var_dump($tstr); return $str; } var_dump(); // $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/YeLAr
function name:  (null)
number of ops:  14
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   INIT_FCALL                                               'var_dump'
          1        DO_ICALL                                                 
   38     2        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'
   39     3        ASSIGN                                                   !0, 'xxxxbbbbbnnn'
   41     4        INIT_FCALL                                               'cn_substr_utf8'
          5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 5
          7        SEND_VAL                                                 0
          8        DO_FCALL                                      0  $5      
          9        ASSIGN                                                   !1, $5
   42    10        INIT_FCALL                                               'var_dump'
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                                 
   44    13      > 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 = 40
Branch analysis from position: 40
2 jumps found. (Code = 44) Position 1 = 43, Position 2 = 20
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 27
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
2 jumps found. (Code = 44) Position 1 = 43, Position 2 = 20
Branch analysis from position: 43
Branch analysis from position: 20
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 38
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
filename:       /in/YeLAr
function name:  cn_substr_utf8
number of ops:  48
compiled vars:  !0 = $str, !1 = $length, !2 = $start, !3 = $ar, !4 = $tstr, !5 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      0
    4     3        STRLEN                                           ~6      !0
          4        ADD                                              ~7      !2, 1
          5        IS_SMALLER                                               ~6, ~7
          6      > JMPZ                                                     ~8, ->8
    6     7    > > RETURN                                                   ''
    8     8    >   INIT_FCALL                                               'preg_match_all'
          9        SEND_VAL                                                 '%2F.%2Fsu'
         10        SEND_VAR                                                 !0
         11        SEND_REF                                                 !3
         12        DO_ICALL                                                 
    9    13        INIT_FCALL                                               'var_dump'
         14        SEND_VAR                                                 !3
         15        DO_ICALL                                                 
   10    16        ASSIGN                                                   !0, ''
   11    17        ASSIGN                                                   !4, ''
   13    18        ASSIGN                                                   !5, 1
         19      > JMP                                                      ->40
   15    20    >   STRLEN                                           ~14     !4
         21        IS_SMALLER                                               ~14, !2
         22      > JMPZ                                                     ~15, ->27
   17    23    >   FETCH_DIM_R                                      ~16     !3, 0
         24        FETCH_DIM_R                                      ~17     ~16, !5
         25        ASSIGN_OP                                     8          !4, ~17
         26      > JMP                                                      ->39
   21    27    >   STRLEN                                           ~19     !0
         28        FETCH_DIM_R                                      ~20     !3, 0
         29        FETCH_DIM_R                                      ~21     ~20, !5
         30        STRLEN                                           ~22     ~21
         31        ADD                                              ~23     !1, ~22
         32        IS_SMALLER                                               ~19, ~23
         33      > JMPZ                                                     ~24, ->38
   23    34    >   FETCH_DIM_R                                      ~25     !3, 0
         35        FETCH_DIM_R                                      ~26     ~25, !5
         36        ASSIGN_OP                                     8          !0, ~26
         37      > JMP                                                      ->39
   27    38    > > JMP                                                      ->43
   13    39    >   PRE_INC                                                  !5
         40    >   FETCH_DIM_IS                                     ~29     !3, 0
         41        ISSET_ISEMPTY_DIM_OBJ                         0          ~29, !5
         42      > JMPNZ                                                    ~30, ->20
   31    43    >   INIT_FCALL                                               'var_dump'
         44        SEND_VAR                                                 !4
         45        DO_ICALL                                                 
   32    46      > RETURN                                                   !0
   33    47*     > RETURN                                                   null

End of function cn_substr_utf8

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.56 ms | 1394 KiB | 18 Q