3v4l.org

run code in 300+ PHP versions simultaneously
<?php function substr_utf8($string, $start, $length) { $chars = $string; $i=0; do { if (preg_match ("/[0-9a-zA-Z]/", $chars[$i])){ $m++; } else { $n++; }//非英文字节, $k = $n/3 + $m/2; $l = $n/3 + $m; $i++; } while ($k < $length); $str1 = mb_substr($string,$start,$l,'utf-8'); return $str1; } $a = '测试这是一个测试'; $a = 'xxxxbbbbbnnn'; $b = substr_utf8($a,0,5); var_dump($b); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ptef2
function name:  (null)
number of ops:  12
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     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'
   21     1        ASSIGN                                                   !0, 'xxxxbbbbbnnn'
   23     2        INIT_FCALL                                               'substr_utf8'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 0
          5        SEND_VAL                                                 5
          6        DO_FCALL                                      0  $4      
          7        ASSIGN                                                   !1, $4
   24     8        INIT_FCALL                                               'var_dump'
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                                 
   26    11      > RETURN                                                   1

Function substr_utf8:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 5
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 5
Branch analysis from position: 24
Branch analysis from position: 5
filename:       /in/Ptef2
function name:  substr_utf8
number of ops:  33
compiled vars:  !0 = $string, !1 = $start, !2 = $length, !3 = $chars, !4 = $i, !5 = $m, !6 = $n, !7 = $k, !8 = $l, !9 = $str1
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    4     3        ASSIGN                                                   !3, !0
    5     4        ASSIGN                                                   !4, 0
    7     5    >   INIT_FCALL                                               'preg_match'
          6        SEND_VAL                                                 '%2F%5B0-9a-zA-Z%5D%2F'
          7        FETCH_DIM_R                                      ~12     !3, !4
          8        SEND_VAL                                                 ~12
          9        DO_ICALL                                         $13     
         10      > JMPZ                                                     $13, ->13
    8    11    >   PRE_INC                                                  !5
         12      > JMP                                                      ->14
   10    13    >   PRE_INC                                                  !6
   12    14    >   DIV                                              ~16     !6, 3
         15        DIV                                              ~17     !5, 2
         16        ADD                                              ~18     ~16, ~17
         17        ASSIGN                                                   !7, ~18
   13    18        DIV                                              ~20     !6, 3
         19        ADD                                              ~21     ~20, !5
         20        ASSIGN                                                   !8, ~21
   14    21        PRE_INC                                                  !4
   15    22        IS_SMALLER                                               !7, !2
         23      > JMPNZ                                                    ~24, ->5
   16    24    >   INIT_FCALL                                               'mb_substr'
         25        SEND_VAR                                                 !0
         26        SEND_VAR                                                 !1
         27        SEND_VAR                                                 !8
         28        SEND_VAL                                                 'utf-8'
         29        DO_ICALL                                         $25     
         30        ASSIGN                                                   !9, $25
   17    31      > RETURN                                                   !9
   18    32*     > RETURN                                                   null

End of function substr_utf8

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.24 ms | 1403 KiB | 20 Q