3v4l.org

run code in 300+ PHP versions simultaneously
<?php // PHP < 7.2 // https://github.com/symfony/polyfill-mbstring/blob/master/Mbstring.php#L708-L730 if( ! function_exists("mb_ord") ) { function mb_ord($s) { if (1 === \strlen($s)) { return \ord($s); } $code = ($s = unpack('C*', substr($s, 0, 4))) ? $s[1] : 0; if (0xF0 <= $code) { return (($code - 0xF0) << 18) + (($s[2] - 0x80) << 12) + (($s[3] - 0x80) << 6) + $s[4] - 0x80; } if (0xE0 <= $code) { return (($code - 0xE0) << 12) + (($s[2] - 0x80) << 6) + $s[3] - 0x80; } if (0xC0 <= $code) { return (($code - 0xC0) << 6) + $s[2] - 0x80; } return $code; } } function ord2seqlen($ord) { if($ord < 128){ return 1; } else if($ord < 224) { return 2; } else if($ord < 240) { return 3; } else if($ord < 248) { return 4; } else { throw new \Exception("No support for 5 or 6 byte sequences."); } } function utf8_seq_iter($input) { for($i=0,$c=strlen($input); $i<$c; ) { $bytes = ord2seqlen(ord($input[$i])); yield substr($input, $i, $bytes); $i += $bytes; } } function escape_codepoint($codepoint, $skip_low=true) { $ord = mb_ord($codepoint); if( $skip_low && $ord < 128 ) { return $codepoint; } else { return sprintf("\\u%04x", $ord); } } $input = "आए थे पर्यटक, खुद ही बह गए"; $output = ''; foreach( utf8_seq_iter($input) as $codepoint ) { $output .= escape_codepoint($codepoint); } var_dump($output);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 18
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 18
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
Branch analysis from position: 6
filename:       /in/neN3a
function name:  (null)
number of ops:  23
compiled vars:  !0 = $input, !1 = $output, !2 = $codepoint
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   INIT_FCALL                                               'function_exists'
          1        SEND_VAL                                                 'mb_ord'
          2        DO_ICALL                                         $3      
          3        BOOL_NOT                                         ~4      $3
          4      > JMPZ                                                     ~4, ->6
    6     5    >   DECLARE_FUNCTION                                         'mb_ord'
   55     6    >   ASSIGN                                                   !0, '%E0%A4%86%E0%A4%8F+%E0%A4%A5%E0%A5%87+%E0%A4%AA%E0%A4%B0%E0%A5%8D%E0%A4%AF%E0%A4%9F%E0%A4%95%2C+%E0%A4%96%E0%A5%81%E0%A4%A6+%E0%A4%B9%E0%A5%80+%E0%A4%AC%E0%A4%B9+%E0%A4%97%E0%A4%8F'
   56     7        ASSIGN                                                   !1, ''
   58     8        INIT_FCALL                                               'utf8_seq_iter'
          9        SEND_VAR                                                 !0
         10        DO_FCALL                                      0  $7      
         11      > FE_RESET_R                                       $8      $7, ->18
         12    > > FE_FETCH_R                                               $8, !2, ->18
   59    13    >   INIT_FCALL                                               'escape_codepoint'
         14        SEND_VAR                                                 !2
         15        DO_FCALL                                      0  $9      
         16        ASSIGN_OP                                     8          !1, $9
   58    17      > JMP                                                      ->12
         18    >   FE_FREE                                                  $8
   62    19        INIT_FCALL                                               'var_dump'
         20        SEND_VAR                                                 !1
         21        DO_ICALL                                                 
         22      > RETURN                                                   1

Function %00mb_ord%2Fin%2FneN3a%3A6%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 22
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 40
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 52
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 52
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 60
Branch analysis from position: 54
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 60
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 40
Branch analysis from position: 26
Branch analysis from position: 40
filename:       /in/neN3a
function name:  mb_ord
number of ops:  62
compiled vars:  !0 = $s, !1 = $code
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    7     1        STRLEN                                           ~2      !0
          2        IS_IDENTICAL                                             ~2, 1
          3      > JMPZ                                                     ~3, ->8
    8     4    >   INIT_FCALL                                               'ord'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $4      
          7      > RETURN                                                   $4
   10     8    >   INIT_FCALL                                               'unpack'
          9        SEND_VAL                                                 'C%2A'
         10        INIT_FCALL                                               'substr'
         11        SEND_VAR                                                 !0
         12        SEND_VAL                                                 0
         13        SEND_VAL                                                 4
         14        DO_ICALL                                         $5      
         15        SEND_VAR                                                 $5
         16        DO_ICALL                                         $6      
         17        ASSIGN                                           ~7      !0, $6
         18      > JMPZ                                                     ~7, ->22
         19    >   FETCH_DIM_R                                      ~8      !0, 1
         20        QM_ASSIGN                                        ~9      ~8
         21      > JMP                                                      ->23
         22    >   QM_ASSIGN                                        ~9      0
         23    >   ASSIGN                                                   !1, ~9
   11    24        IS_SMALLER_OR_EQUAL                                      240, !1
         25      > JMPZ                                                     ~11, ->40
   12    26    >   SUB                                              ~12     !1, 240
         27        SL                                               ~13     ~12, 18
         28        FETCH_DIM_R                                      ~14     !0, 2
         29        SUB                                              ~15     ~14, 128
         30        SL                                               ~16     ~15, 12
         31        ADD                                              ~17     ~13, ~16
         32        FETCH_DIM_R                                      ~18     !0, 3
         33        SUB                                              ~19     ~18, 128
         34        SL                                               ~20     ~19, 6
         35        ADD                                              ~21     ~17, ~20
         36        FETCH_DIM_R                                      ~22     !0, 4
         37        ADD                                              ~23     ~21, ~22
         38        SUB                                              ~24     ~23, 128
         39      > RETURN                                                   ~24
   14    40    >   IS_SMALLER_OR_EQUAL                                      224, !1
         41      > JMPZ                                                     ~25, ->52
   15    42    >   SUB                                              ~26     !1, 224
         43        SL                                               ~27     ~26, 12
         44        FETCH_DIM_R                                      ~28     !0, 2
         45        SUB                                              ~29     ~28, 128
         46        SL                                               ~30     ~29, 6
         47        ADD                                              ~31     ~27, ~30
         48        FETCH_DIM_R                                      ~32     !0, 3
         49        ADD                                              ~33     ~31, ~32
         50        SUB                                              ~34     ~33, 128
         51      > RETURN                                                   ~34
   17    52    >   IS_SMALLER_OR_EQUAL                                      192, !1
         53      > JMPZ                                                     ~35, ->60
   18    54    >   SUB                                              ~36     !1, 192
         55        SL                                               ~37     ~36, 6
         56        FETCH_DIM_R                                      ~38     !0, 2
         57        ADD                                              ~39     ~37, ~38
         58        SUB                                              ~40     ~39, 128
         59      > RETURN                                                   ~40
   20    60    > > RETURN                                                   !1
   21    61*     > RETURN                                                   null

End of function %00mb_ord%2Fin%2FneN3a%3A6%240

Function ord2seqlen:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/neN3a
function name:  ord2seqlen
number of ops:  22
compiled vars:  !0 = $ord
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        IS_SMALLER                                               !0, 128
          2      > JMPZ                                                     ~1, ->5
   26     3    > > RETURN                                                   1
          4*       JMP                                                      ->21
   27     5    >   IS_SMALLER                                               !0, 224
          6      > JMPZ                                                     ~2, ->9
   28     7    > > RETURN                                                   2
          8*       JMP                                                      ->21
   29     9    >   IS_SMALLER                                               !0, 240
         10      > JMPZ                                                     ~3, ->13
   30    11    > > RETURN                                                   3
         12*       JMP                                                      ->21
   31    13    >   IS_SMALLER                                               !0, 248
         14      > JMPZ                                                     ~4, ->17
   32    15    > > RETURN                                                   4
         16*       JMP                                                      ->21
   34    17    >   NEW                                              $5      'Exception'
         18        SEND_VAL_EX                                              'No+support+for+5+or+6+byte+sequences.'
         19        DO_FCALL                                      0          
         20      > THROW                                         0          $5
   36    21*     > RETURN                                                   null

End of function ord2seqlen

Function utf8_seq_iter:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 6
Branch analysis from position: 23
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 6
Branch analysis from position: 23
Branch analysis from position: 6
filename:       /in/neN3a
function name:  utf8_seq_iter
number of ops:  24
compiled vars:  !0 = $input, !1 = $i, !2 = $c, !3 = $bytes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
   39     2        ASSIGN                                                   !1, 0
          3        STRLEN                                           ~5      !0
          4        ASSIGN                                                   !2, ~5
          5      > JMP                                                      ->21
   40     6    >   INIT_FCALL                                               'ord2seqlen'
          7        INIT_FCALL                                               'ord'
          8        FETCH_DIM_R                                      ~7      !0, !1
          9        SEND_VAL                                                 ~7
         10        DO_ICALL                                         $8      
         11        SEND_VAR                                                 $8
         12        DO_FCALL                                      0  $9      
         13        ASSIGN                                                   !3, $9
   41    14        INIT_FCALL                                               'substr'
         15        SEND_VAR                                                 !0
         16        SEND_VAR                                                 !1
         17        SEND_VAR                                                 !3
         18        DO_ICALL                                         $11     
         19        YIELD                                                    $11
   42    20        ASSIGN_OP                                     1          !1, !3
   39    21    >   IS_SMALLER                                               !1, !2
         22      > JMPNZ                                                    ~14, ->6
   44    23    > > GENERATOR_RETURN                                         

End of function utf8_seq_iter

Function escape_codepoint:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/neN3a
function name:  escape_codepoint
number of ops:  18
compiled vars:  !0 = $codepoint, !1 = $skip_low, !2 = $ord
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <true>
   47     2        INIT_FCALL                                               'mb_ord'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $3      
          5        ASSIGN                                                   !2, $3
   48     6      > JMPZ_EX                                          ~5      !1, ->9
          7    >   IS_SMALLER                                       ~6      !2, 128
          8        BOOL                                             ~5      ~6
          9    > > JMPZ                                                     ~5, ->12
   49    10    > > RETURN                                                   !0
         11*       JMP                                                      ->17
   51    12    >   INIT_FCALL                                               'sprintf'
         13        SEND_VAL                                                 '%5Cu%2504x'
         14        SEND_VAR                                                 !2
         15        DO_ICALL                                         $7      
         16      > RETURN                                                   $7
   53    17*     > RETURN                                                   null

End of function escape_codepoint

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
204.68 ms | 1415 KiB | 30 Q