3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = <<<EOD http://localhost:8000/search/fa?q=sth http://localhost:8000/search?q=sth http://localhost:8000/search http://localhost:8000/search/fa EOD; preg_match_all('/^(.*?)\/(\w{2,})(?:\?(.*?)|)$/mis',$str,$p); echo '<pre/>'; $final_array = array(); $i = 0; foreach($p[1] as $myP){ if( $p[2][$i] == 'fa'){ $p[2][$i] = 'en'; } else if($p[2][$i] != 'en') { $p[2][$i] = $p[2][$i].'/'.'en'; } $final_array[$i] = $myP.'/'.$p[2][$i]; $i++; } var_dump($final_array);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 39
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 39
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 20
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 31
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 31
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
filename:       /in/pe1YY
function name:  (null)
number of ops:  44
compiled vars:  !0 = $str, !1 = $p, !2 = $final_array, !3 = $i, !4 = $myP
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'http%3A%2F%2Flocalhost%3A8000%2Fsearch%2Ffa%3Fq%3Dsth%0A%0Ahttp%3A%2F%2Flocalhost%3A8000%2Fsearch%3Fq%3Dsth%0A%0Ahttp%3A%2F%2Flocalhost%3A8000%2Fsearch%0A%0Ahttp%3A%2F%2Flocalhost%3A8000%2Fsearch%2Ffa%0A'
   12     1        INIT_FCALL                                               'preg_match_all'
          2        SEND_VAL                                                 '%2F%5E%28.%2A%3F%29%5C%2F%28%5Cw%7B2%2C%7D%29%28%3F%3A%5C%3F%28.%2A%3F%29%7C%29%24%2Fmis'
          3        SEND_VAR                                                 !0
          4        SEND_REF                                                 !1
          5        DO_ICALL                                                 
   13     6        ECHO                                                     '%3Cpre%2F%3E'
   14     7        ASSIGN                                                   !2, <array>
   15     8        ASSIGN                                                   !3, 0
   16     9        FETCH_DIM_R                                      ~9      !1, 1
         10      > FE_RESET_R                                       $10     ~9, ->39
         11    > > FE_FETCH_R                                               $10, !4, ->39
   17    12    >   FETCH_DIM_R                                      ~11     !1, 2
         13        FETCH_DIM_R                                      ~12     ~11, !3
         14        IS_EQUAL                                                 ~12, 'fa'
         15      > JMPZ                                                     ~13, ->20
   18    16    >   FETCH_DIM_W                                      $14     !1, 2
         17        ASSIGN_DIM                                               $14, !3
         18        OP_DATA                                                  'en'
         19      > JMP                                                      ->31
   19    20    >   FETCH_DIM_R                                      ~16     !1, 2
         21        FETCH_DIM_R                                      ~17     ~16, !3
         22        IS_NOT_EQUAL                                             ~17, 'en'
         23      > JMPZ                                                     ~18, ->31
   20    24    >   FETCH_DIM_R                                      ~21     !1, 2
         25        FETCH_DIM_R                                      ~22     ~21, !3
         26        CONCAT                                           ~23     ~22, '%2F'
         27        CONCAT                                           ~24     ~23, 'en'
         28        FETCH_DIM_W                                      $19     !1, 2
         29        ASSIGN_DIM                                               $19, !3
         30        OP_DATA                                                  ~24
   22    31    >   CONCAT                                           ~26     !4, '%2F'
         32        FETCH_DIM_R                                      ~27     !1, 2
         33        FETCH_DIM_R                                      ~28     ~27, !3
         34        CONCAT                                           ~29     ~26, ~28
         35        ASSIGN_DIM                                               !2, !3
         36        OP_DATA                                                  ~29
   23    37        PRE_INC                                                  !3
   16    38      > JMP                                                      ->11
         39    >   FE_FREE                                                  $10
   27    40        INIT_FCALL                                               'var_dump'
         41        SEND_VAR                                                 !2
         42        DO_ICALL                                                 
         43      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.44 ms | 1400 KiB | 17 Q