3v4l.org

run code in 500+ PHP versions simultaneously
<?php final class NonUtfToUtfOffset { /** @var int[] */ private $utfMap = []; public function __construct(string $content) { $contentLength = mb_strlen($content); for ($offset = 0; $offset < $contentLength; $offset ++) { $char = mb_substr($content, $offset, 1); $nonUtfLength = strlen($char); for ($charOffset = 0; $charOffset < $nonUtfLength; $charOffset ++) { $this->utfMap[] = $offset; } } } public function convertOffset(int $nonUtfOffset): int { return $this->utfMap[$nonUtfOffset]; } } $content = 'aą bać d'; $offsetConverter = new NonUtfToUtfOffset($content); preg_match_all('#(bać)#ui', $content, $m, PREG_OFFSET_CAPTURE); foreach ($m[1] as [$word, $offset]) { echo "bad: " . mb_substr($content, $offset, mb_strlen($word))."\n"; echo "good: " . mb_substr($content, $offsetConverter->convertOffset($offset), mb_strlen($word))."\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 45
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 45
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
filename:       /in/8Y32J
function name:  (null)
number of ops:  47
compiled vars:  !0 = $content, !1 = $offsetConverter, !2 = $m, !3 = $word, !4 = $offset
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   29     0  E >   ASSIGN                                                       !0, 'a%C4%85+ba%C4%87+d'
   30     1        NEW                                                  $6      'NonUtfToUtfOffset'
          2        SEND_VAR_EX                                                  !0
          3        DO_FCALL                                          0          
          4        ASSIGN                                                       !1, $6
   32     5        INIT_FCALL                                                   'preg_match_all'
          6        SEND_VAL                                                     '%23%28ba%C4%87%29%23ui'
          7        SEND_VAR                                                     !0
          8        SEND_REF                                                     !2
          9        SEND_VAL                                                     256
         10        DO_ICALL                                                     
   34    11        FETCH_DIM_R                                          ~10     !2, 1
         12      > FE_RESET_R                                           $11     ~10, ->45
         13    > > FE_FETCH_R                                                   $11, $12, ->45
         14    >   FETCH_LIST_R                                         $13     $12, 0
         15        ASSIGN                                                       !3, $13
         16        FETCH_LIST_R                                         $15     $12, 1
         17        ASSIGN                                                       !4, $15
         18        FREE                                                         $12
   35    19        INIT_FCALL                                                   'mb_substr'
         20        SEND_VAR                                                     !0
         21        SEND_VAR                                                     !4
         22        INIT_FCALL                                                   'mb_strlen'
         23        SEND_VAR                                                     !3
         24        DO_ICALL                                             $17     
         25        SEND_VAR                                                     $17
         26        DO_ICALL                                             $18     
         27        CONCAT                                               ~19     'bad%3A+', $18
         28        CONCAT                                               ~20     ~19, '%0A'
         29        ECHO                                                         ~20
   36    30        INIT_FCALL                                                   'mb_substr'
         31        SEND_VAR                                                     !0
         32        INIT_METHOD_CALL                                             !1, 'convertOffset'
         33        SEND_VAR_EX                                                  !4
         34        DO_FCALL                                          0  $21     
         35        SEND_VAR                                                     $21
         36        INIT_FCALL                                                   'mb_strlen'
         37        SEND_VAR                                                     !3
         38        DO_ICALL                                             $22     
         39        SEND_VAR                                                     $22
         40        DO_ICALL                                             $23     
         41        CONCAT                                               ~24     'good%3A+', $23
         42        CONCAT                                               ~25     ~24, '%0A'
         43        ECHO                                                         ~25
   34    44      > JMP                                                          ->13
         45    >   FE_FREE                                                      $11
   37    46      > RETURN                                                       1

Class NonUtfToUtfOffset:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 7
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 17
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 7
Branch analysis from position: 26
Branch analysis from position: 7
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 17
Branch analysis from position: 23
Branch analysis from position: 17
filename:       /in/8Y32J
function name:  __construct
number of ops:  27
compiled vars:  !0 = $content, !1 = $contentLength, !2 = $offset, !3 = $char, !4 = $nonUtfLength, !5 = $charOffset
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    9     0  E >   RECV                                                 !0      
   11     1        INIT_FCALL                                                   'mb_strlen'
          2        SEND_VAR                                                     !0
          3        DO_ICALL                                             $6      
          4        ASSIGN                                                       !1, $6
   13     5        ASSIGN                                                       !2, 0
          6      > JMP                                                          ->24
   14     7    >   INIT_FCALL                                                   'mb_substr'
          8        SEND_VAR                                                     !0
          9        SEND_VAR                                                     !2
         10        SEND_VAL                                                     1
         11        DO_ICALL                                             $9      
         12        ASSIGN                                                       !3, $9
   15    13        STRLEN                                               ~11     !3
         14        ASSIGN                                                       !4, ~11
   17    15        ASSIGN                                                       !5, 0
         16      > JMP                                                          ->21
   18    17    >   FETCH_OBJ_W                                          $14     'utfMap'
         18        ASSIGN_DIM                                                   $14
         19        OP_DATA                                                      !2
   17    20        PRE_INC                                                      !5
         21    >   IS_SMALLER                                                   !5, !4
         22      > JMPNZ                                                        ~17, ->17
   13    23    >   PRE_INC                                                      !2
         24    >   IS_SMALLER                                                   !2, !1
         25      > JMPNZ                                                        ~19, ->7
   21    26    > > RETURN                                                       null

End of function __construct

Function convertoffset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8Y32J
function name:  convertOffset
number of ops:  7
compiled vars:  !0 = $nonUtfOffset
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   23     0  E >   RECV                                                 !0      
   25     1        FETCH_OBJ_R                                          ~1      'utfMap'
          2        FETCH_DIM_R                                          ~2      ~1, !0
          3        VERIFY_RETURN_TYPE                                           ~2
          4      > RETURN                                                       ~2
   26     5*       VERIFY_RETURN_TYPE                                           
          6*     > RETURN                                                       null

End of function convertoffset

End of class NonUtfToUtfOffset.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
178.69 ms | 3302 KiB | 16 Q