3v4l.org

run code in 300+ PHP versions simultaneously
<?php function str_split_unicode($str, $l = 0) { if ($l > 0) { $ret = array(); $len = mb_strlen($str, "UTF-8"); for ($i = 0; $i < $len; $i += $l) { $ret[] = mb_substr($str, $i, $l, "UTF-8"); } return $ret; } return preg_split("//u", $str, -1, PREG_SPLIT_NO_EMPTY); } $s = '中华人民abc共和\x01国'; echo $s; print_r(str_split_unicode($s)); print_r(str_split_unicode($s, 3)); for($i =0 ; $i < length($s) ; $i++) {echo $sub_str = mb_substr($s, $i, 1);}
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 17
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 17
Branch analysis from position: 30
Branch analysis from position: 17
filename:       /in/Ss9Jl
function name:  (null)
number of ops:  31
compiled vars:  !0 = $s, !1 = $i, !2 = $sub_str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   ASSIGN                                                   !0, '%E4%B8%AD%E5%8D%8E%E4%BA%BA%E6%B0%91abc%E5%85%B1%E5%92%8C%5Cx01%E5%9B%BD'
   14     1        ECHO                                                     !0
   15     2        INIT_FCALL                                               'print_r'
          3        INIT_FCALL                                               'str_split_unicode'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $4      
          6        SEND_VAR                                                 $4
          7        DO_ICALL                                                 
   16     8        INIT_FCALL                                               'print_r'
          9        INIT_FCALL                                               'str_split_unicode'
         10        SEND_VAR                                                 !0
         11        SEND_VAL                                                 3
         12        DO_FCALL                                      0  $6      
         13        SEND_VAR                                                 $6
         14        DO_ICALL                                                 
   18    15        ASSIGN                                                   !1, 0
         16      > JMP                                                      ->25
         17    >   INIT_FCALL                                               'mb_substr'
         18        SEND_VAR                                                 !0
         19        SEND_VAR                                                 !1
         20        SEND_VAL                                                 1
         21        DO_ICALL                                         $9      
         22        ASSIGN                                           ~10     !2, $9
         23        ECHO                                                     ~10
         24        PRE_INC                                                  !1
         25    >   INIT_FCALL_BY_NAME                                       'length'
         26        SEND_VAR_EX                                              !0
         27        DO_FCALL                                      0  $12     
         28        IS_SMALLER                                               !1, $12
         29      > JMPNZ                                                    ~13, ->17
         30    > > RETURN                                                   1

Function str_split_unicode:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 24
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 12
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 12
Branch analysis from position: 23
Branch analysis from position: 12
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ss9Jl
function name:  str_split_unicode
number of ops:  32
compiled vars:  !0 = $str, !1 = $l, !2 = $ret, !3 = $len, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
    3     2        IS_SMALLER                                               0, !1
          3      > JMPZ                                                     ~5, ->24
    4     4    >   ASSIGN                                                   !2, <array>
    5     5        INIT_FCALL                                               'mb_strlen'
          6        SEND_VAR                                                 !0
          7        SEND_VAL                                                 'UTF-8'
          8        DO_ICALL                                         $7      
          9        ASSIGN                                                   !3, $7
    6    10        ASSIGN                                                   !4, 0
         11      > JMP                                                      ->21
    7    12    >   INIT_FCALL                                               'mb_substr'
         13        SEND_VAR                                                 !0
         14        SEND_VAR                                                 !4
         15        SEND_VAR                                                 !1
         16        SEND_VAL                                                 'UTF-8'
         17        DO_ICALL                                         $11     
         18        ASSIGN_DIM                                               !2
         19        OP_DATA                                                  $11
    6    20        ASSIGN_OP                                     1          !4, !1
         21    >   IS_SMALLER                                               !4, !3
         22      > JMPNZ                                                    ~13, ->12
    9    23    > > RETURN                                                   !2
   11    24    >   INIT_FCALL                                               'preg_split'
         25        SEND_VAL                                                 '%2F%2Fu'
         26        SEND_VAR                                                 !0
         27        SEND_VAL                                                 -1
         28        SEND_VAL                                                 1
         29        DO_ICALL                                         $14     
         30      > RETURN                                                   $14
   12    31*     > RETURN                                                   null

End of function str_split_unicode

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.97 ms | 1394 KiB | 23 Q