3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = 'Hello {{ name }}, nice to meet you.'; define('TAG_OPEN', '{{'); define('TAG_CLOSE', '}}'); define('STATE_TEXT', 'STATE_TEXT'); define('STATE_IN_TAG', 'STATE_IN_TAG'); function isOpenTag($string, $index) { return TAG_OPEN === substr($string, $index, strlen(TAG_OPEN)); } function isCloseTag($string, $index) { return TAG_CLOSE === substr($string, $index, strlen(TAG_CLOSE)); } function isText($string, $index) { return ! (isOpenTag($string, $index) || isCloseTag($string, $index)); } $state = STATE_TEXT; for($index = 0; $index < strlen($string); $index++) { if (isText($string, $index) && $state != STATE_IN_TAG) { continue; } if (isOpenTag($string, $index)) { $state = STATE_IN_TAG; $index += strlen(TAG_OPEN) - 1; continue; } if (isText($string, $index) && $state = STATE_IN_TAG) { echo $index, ' ', $string[$index], PHP_EOL; } if (isCloseTag($string, $index)) { $state = STATE_TEXT; $index += strlen(TAG_CLOSE) - 1; continue; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
2 jumps found. (Code = 44) Position 1 = 73, Position 2 = 21
Branch analysis from position: 73
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
2 jumps found. (Code = 46) Position 1 = 26, Position 2 = 29
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 31
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 69
Branch analysis from position: 69
2 jumps found. (Code = 44) Position 1 = 73, Position 2 = 21
Branch analysis from position: 73
Branch analysis from position: 21
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 43
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 69
Branch analysis from position: 69
Branch analysis from position: 43
2 jumps found. (Code = 46) Position 1 = 48, Position 2 = 51
Branch analysis from position: 48
2 jumps found. (Code = 43) Position 1 = 52, Position 2 = 57
Branch analysis from position: 52
2 jumps found. (Code = 43) Position 1 = 62, Position 2 = 69
Branch analysis from position: 62
1 jumps found. (Code = 42) Position 1 = 69
Branch analysis from position: 69
Branch analysis from position: 69
Branch analysis from position: 57
Branch analysis from position: 51
Branch analysis from position: 29
filename:       /in/DFjPm
function name:  (null)
number of ops:  74
compiled vars:  !0 = $string, !1 = $state, !2 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'Hello+%7B%7B+name+%7D%7D%2C+nice+to+meet+you.'
    4     1        INIT_FCALL                                               'define'
          2        SEND_VAL                                                 'TAG_OPEN'
          3        SEND_VAL                                                 '%7B%7B'
          4        DO_ICALL                                                 
    5     5        INIT_FCALL                                               'define'
          6        SEND_VAL                                                 'TAG_CLOSE'
          7        SEND_VAL                                                 '%7D%7D'
          8        DO_ICALL                                                 
    6     9        INIT_FCALL                                               'define'
         10        SEND_VAL                                                 'STATE_TEXT'
         11        SEND_VAL                                                 'STATE_TEXT'
         12        DO_ICALL                                                 
    7    13        INIT_FCALL                                               'define'
         14        SEND_VAL                                                 'STATE_IN_TAG'
         15        SEND_VAL                                                 'STATE_IN_TAG'
         16        DO_ICALL                                                 
   21    17        FETCH_CONSTANT                                   ~8      'STATE_TEXT'
         18        ASSIGN                                                   !1, ~8
   23    19        ASSIGN                                                   !2, 0
         20      > JMP                                                      ->70
   25    21    >   INIT_FCALL                                               'istext'
         22        SEND_VAR                                                 !0
         23        SEND_VAR                                                 !2
         24        DO_FCALL                                      0  $11     
         25      > JMPZ_EX                                          ~12     $11, ->29
         26    >   FETCH_CONSTANT                                   ~13     'STATE_IN_TAG'
         27        IS_NOT_EQUAL                                     ~14     !1, ~13
         28        BOOL                                             ~12     ~14
         29    > > JMPZ                                                     ~12, ->31
   26    30    > > JMP                                                      ->69
   29    31    >   INIT_FCALL                                               'isopentag'
         32        SEND_VAR                                                 !0
         33        SEND_VAR                                                 !2
         34        DO_FCALL                                      0  $15     
         35      > JMPZ                                                     $15, ->43
   30    36    >   FETCH_CONSTANT                                   ~16     'STATE_IN_TAG'
         37        ASSIGN                                                   !1, ~16
   31    38        FETCH_CONSTANT                                   ~18     'TAG_OPEN'
         39        STRLEN                                           ~19     ~18
         40        SUB                                              ~20     ~19, 1
         41        ASSIGN_OP                                     1          !2, ~20
   32    42      > JMP                                                      ->69
   35    43    >   INIT_FCALL                                               'istext'
         44        SEND_VAR                                                 !0
         45        SEND_VAR                                                 !2
         46        DO_FCALL                                      0  $22     
         47      > JMPZ_EX                                          ~23     $22, ->51
         48    >   FETCH_CONSTANT                                   ~24     'STATE_IN_TAG'
         49        ASSIGN                                           ~25     !1, ~24
         50        BOOL                                             ~23     ~25
         51    > > JMPZ                                                     ~23, ->57
   36    52    >   ECHO                                                     !2
         53        ECHO                                                     '+'
         54        FETCH_DIM_R                                      ~26     !0, !2
         55        ECHO                                                     ~26
         56        ECHO                                                     '%0A'
   39    57    >   INIT_FCALL                                               'isclosetag'
         58        SEND_VAR                                                 !0
         59        SEND_VAR                                                 !2
         60        DO_FCALL                                      0  $27     
         61      > JMPZ                                                     $27, ->69
   40    62    >   FETCH_CONSTANT                                   ~28     'STATE_TEXT'
         63        ASSIGN                                                   !1, ~28
   41    64        FETCH_CONSTANT                                   ~30     'TAG_CLOSE'
         65        STRLEN                                           ~31     ~30
         66        SUB                                              ~32     ~31, 1
         67        ASSIGN_OP                                     1          !2, ~32
   42    68      > JMP                                                      ->69
   23    69    >   PRE_INC                                                  !2
         70    >   STRLEN                                           ~35     !0
         71        IS_SMALLER                                               !2, ~35
         72      > JMPNZ                                                    ~36, ->21
   44    73    > > RETURN                                                   1

Function isopentag:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DFjPm
function name:  isOpenTag
number of ops:  13
compiled vars:  !0 = $string, !1 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   10     2        FETCH_CONSTANT                                   ~2      'TAG_OPEN'
          3        INIT_FCALL                                               'substr'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        FETCH_CONSTANT                                   ~3      'TAG_OPEN'
          7        STRLEN                                           ~4      ~3
          8        SEND_VAL                                                 ~4
          9        DO_ICALL                                         $5      
         10        IS_IDENTICAL                                     ~6      $5, ~2
         11      > RETURN                                                   ~6
   11    12*     > RETURN                                                   null

End of function isopentag

Function isclosetag:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DFjPm
function name:  isCloseTag
number of ops:  13
compiled vars:  !0 = $string, !1 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   14     2        FETCH_CONSTANT                                   ~2      'TAG_CLOSE'
          3        INIT_FCALL                                               'substr'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        FETCH_CONSTANT                                   ~3      'TAG_CLOSE'
          7        STRLEN                                           ~4      ~3
          8        SEND_VAL                                                 ~4
          9        DO_ICALL                                         $5      
         10        IS_IDENTICAL                                     ~6      $5, ~2
         11      > RETURN                                                   ~6
   15    12*     > RETURN                                                   null

End of function isclosetag

Function istext:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/DFjPm
function name:  isText
number of ops:  15
compiled vars:  !0 = $string, !1 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   18     2        INIT_FCALL                                               'isopentag'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $2      
          6      > JMPNZ_EX                                         ~3      $2, ->12
          7    >   INIT_FCALL                                               'isclosetag'
          8        SEND_VAR                                                 !0
          9        SEND_VAR                                                 !1
         10        DO_FCALL                                      0  $4      
         11        BOOL                                             ~3      $4
         12    >   BOOL_NOT                                         ~5      ~3
         13      > RETURN                                                   ~5
   19    14*     > RETURN                                                   null

End of function istext

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.18 ms | 1411 KiB | 23 Q