3v4l.org

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

Function isopentag:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/X50aZ
function name:  isOpenTag
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_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
   15    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/X50aZ
function name:  isCloseTag
number of ops:  13
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        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
   19    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/X50aZ
function name:  isText
number of ops:  15
compiled vars:  !0 = $string, !1 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   22     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
   23    14*     > RETURN                                                   null

End of function istext

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.33 ms | 1415 KiB | 23 Q