3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(E_ALL); function buildPosArr( $s, $d ) { $pArr = []; $needle = ""; $endstr = 0; for( $i=0, $max=count( $d ); $i < $max-1; $i++) { $needle = $d[$i]; if( ($pos = stripos( $s, $needle ) ) !== false){ $pArr[$pos] = $needle; if ($needle == "plain") break; // done for ( $j = $pos, $max = ($pos + strlen($needle)); $j < $max; $j++) { $s[$j] = "\0"; } // end for }// end if }// end for return $pArr; } function assign2str(&$s,$k,$v){ $max = strlen($v); for($i = $k, $j=0; $j < $max; $j++,$i++) { $s[$i] = $v[$j]; } } $str = "THERAININSPAINSTAYSMAINLYINTHEPLAIN."; echo "Before: $str\n\n"; $d = ["The", "rain", "in", "Spain", "stays", "mainly", "in", "the", "plain"]; $arr = buildPosArr( $str, $d ); foreach ($arr as $key => $value) { switch($value) { case "The": $value = strtolower($value); break; case "rain": $value = ucfirst($value); break; case "in": $value = ucfirst($value); case "Spain": break; case "stays": $value = strtoupper($value); break; case "mainly": break; case "plain": $value = ucfirst($value); default: break; } assign2str( $str,$key,$value ); } echo " After: ",$str;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 65
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 65
Branch analysis from position: 16
9 jumps found. (Code = 188) Position 1 = 33, Position 2 = 38, Position 3 = 43, Position 4 = 47, Position 5 = 48, Position 6 = 53, Position 7 = 54, Position 8 = 58, Position 9 = 18
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
Branch analysis from position: 47
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
Branch analysis from position: 58
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 33
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 38
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 43
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 47
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 48
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 53
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 54
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 58
Branch analysis from position: 58
Branch analysis from position: 54
Branch analysis from position: 53
Branch analysis from position: 48
Branch analysis from position: 47
Branch analysis from position: 43
Branch analysis from position: 38
Branch analysis from position: 33
Branch analysis from position: 65
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 65
filename:       /in/W32LT
function name:  (null)
number of ops:  69
compiled vars:  !0 = $str, !1 = $d, !2 = $arr, !3 = $value, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'error_reporting'
          1        SEND_VAL                                                 32767
          2        DO_ICALL                                                 
   36     3        ASSIGN                                                   !0, 'THERAININSPAINSTAYSMAINLYINTHEPLAIN.'
   37     4        ROPE_INIT                                     3  ~8      'Before%3A+'
          5        ROPE_ADD                                      1  ~8      ~8, !0
          6        ROPE_END                                      2  ~7      ~8, '%0A%0A'
          7        ECHO                                                     ~7
   39     8        ASSIGN                                                   !1, <array>
   49     9        INIT_FCALL                                               'buildposarr'
         10        SEND_VAR                                                 !0
         11        SEND_VAR                                                 !1
         12        DO_FCALL                                      0  $11     
         13        ASSIGN                                                   !2, $11
   51    14      > FE_RESET_R                                       $13     !2, ->65
         15    > > FE_FETCH_R                                       ~14     $13, !3, ->65
         16    >   ASSIGN                                                   !4, ~14
   52    17      > SWITCH_STRING                                            !3, [ 'The':->33, 'rain':->38, 'in':->43, 'Spain':->47, 'stays':->48, 'mainly':->53, 'plain':->54, ], ->58
   54    18    >   IS_EQUAL                                                 !3, 'The'
         19      > JMPNZ                                                    ~16, ->33
   57    20    >   IS_EQUAL                                                 !3, 'rain'
         21      > JMPNZ                                                    ~16, ->38
   60    22    >   IS_EQUAL                                                 !3, 'in'
         23      > JMPNZ                                                    ~16, ->43
   62    24    >   IS_EQUAL                                                 !3, 'Spain'
         25      > JMPNZ                                                    ~16, ->47
   64    26    >   IS_EQUAL                                                 !3, 'stays'
         27      > JMPNZ                                                    ~16, ->48
   67    28    >   IS_EQUAL                                                 !3, 'mainly'
         29      > JMPNZ                                                    ~16, ->53
   69    30    >   IS_EQUAL                                                 !3, 'plain'
         31      > JMPNZ                                                    ~16, ->54
         32    > > JMP                                                      ->58
   55    33    >   INIT_FCALL                                               'strtolower'
         34        SEND_VAR                                                 !3
         35        DO_ICALL                                         $17     
         36        ASSIGN                                                   !3, $17
   56    37      > JMP                                                      ->59
   58    38    >   INIT_FCALL                                               'ucfirst'
         39        SEND_VAR                                                 !3
         40        DO_ICALL                                         $19     
         41        ASSIGN                                                   !3, $19
   59    42      > JMP                                                      ->59
   61    43    >   INIT_FCALL                                               'ucfirst'
         44        SEND_VAR                                                 !3
         45        DO_ICALL                                         $21     
         46        ASSIGN                                                   !3, $21
   63    47    > > JMP                                                      ->59
   65    48    >   INIT_FCALL                                               'strtoupper'
         49        SEND_VAR                                                 !3
         50        DO_ICALL                                         $23     
         51        ASSIGN                                                   !3, $23
   66    52      > JMP                                                      ->59
   68    53    > > JMP                                                      ->59
   70    54    >   INIT_FCALL                                               'ucfirst'
         55        SEND_VAR                                                 !3
         56        DO_ICALL                                         $25     
         57        ASSIGN                                                   !3, $25
   72    58    > > JMP                                                      ->59
   75    59    >   INIT_FCALL                                               'assign2str'
         60        SEND_REF                                                 !0
         61        SEND_VAR                                                 !4
         62        SEND_VAR                                                 !3
         63        DO_FCALL                                      0          
   51    64      > JMP                                                      ->15
         65    >   FE_FREE                                                  $13
   78    66        ECHO                                                     '+After%3A+'
         67        ECHO                                                     !0
         68      > RETURN                                                   1

Function buildposarr:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 9
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 33
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 23
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 28
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 9
Branch analysis from position: 37
Branch analysis from position: 9
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 28
Branch analysis from position: 33
Branch analysis from position: 28
Branch analysis from position: 33
filename:       /in/W32LT
function name:  buildPosArr
number of ops:  39
compiled vars:  !0 = $s, !1 = $d, !2 = $pArr, !3 = $needle, !4 = $endstr, !5 = $i, !6 = $max, !7 = $pos, !8 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2        ASSIGN                                                   !2, <array>
    8     3        ASSIGN                                                   !3, ''
    9     4        ASSIGN                                                   !4, 0
   11     5        ASSIGN                                                   !5, 0
          6        COUNT                                            ~13     !1
          7        ASSIGN                                                   !6, ~13
          8      > JMP                                                      ->34
   12     9    >   FETCH_DIM_R                                      ~15     !1, !5
         10        ASSIGN                                                   !3, ~15
   13    11        INIT_FCALL                                               'stripos'
         12        SEND_VAR                                                 !0
         13        SEND_VAR                                                 !3
         14        DO_ICALL                                         $17     
         15        ASSIGN                                           ~18     !7, $17
         16        TYPE_CHECK                                  1018          ~18
         17      > JMPZ                                                     ~19, ->33
   14    18    >   ASSIGN_DIM                                               !2, !7
         19        OP_DATA                                                  !3
   15    20        IS_EQUAL                                                 !3, 'plain'
         21      > JMPZ                                                     ~21, ->23
         22    > > JMP                                                      ->37
   16    23    >   ASSIGN                                                   !8, !7
         24        STRLEN                                           ~23     !3
         25        ADD                                              ~24     !7, ~23
         26        ASSIGN                                                   !6, ~24
         27      > JMP                                                      ->31
   17    28    >   ASSIGN_DIM                                               !0, !8
         29        OP_DATA                                                  '%00'
   16    30        PRE_INC                                                  !8
         31    >   IS_SMALLER                                               !8, !6
         32      > JMPNZ                                                    ~28, ->28
   11    33    >   PRE_INC                                                  !5
         34    >   SUB                                              ~30     !6, 1
         35        IS_SMALLER                                               !5, ~30
         36      > JMPNZ                                                    ~31, ->9
   22    37    > > RETURN                                                   !2
   23    38*     > RETURN                                                   null

End of function buildposarr

Function assign2str:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 8
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 8
Branch analysis from position: 15
Branch analysis from position: 8
filename:       /in/W32LT
function name:  assign2str
number of ops:  16
compiled vars:  !0 = $s, !1 = $k, !2 = $v, !3 = $max, !4 = $i, !5 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   29     3        STRLEN                                           ~6      !2
          4        ASSIGN                                                   !3, ~6
   30     5        ASSIGN                                                   !4, !1
          6        ASSIGN                                                   !5, 0
          7      > JMP                                                      ->13
   31     8    >   FETCH_DIM_R                                      ~11     !2, !5
          9        ASSIGN_DIM                                               !0, !4
         10        OP_DATA                                                  ~11
   30    11        PRE_INC                                                  !5
         12        PRE_INC                                                  !4
         13    >   IS_SMALLER                                               !5, !3
         14      > JMPNZ                                                    ~14, ->8
   33    15    > > RETURN                                                   null

End of function assign2str

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.61 ms | 1411 KiB | 25 Q