3v4l.org

run code in 300+ PHP versions simultaneously
<?php $sentence = '{Please|Just} make this {cool|awesome|random} test sentence {rotate {quickly|fast} and random|spin and be random}'; function sentence_spinning($str) { while (@$count !== 0) { $str = preg_replace_callback('#\{([^{}]*)\}#', function($matches) { return explode('|', $matches[1])[mt_rand(0, substr_count($matches[1], '|'))]; }, $str, -1, $count); } return $str; } echo $sentence, PHP_EOL, sentence_spinning($sentence);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GLvim
function name:  (null)
number of ops:  8
compiled vars:  !0 = $sentence
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%7BPlease%7CJust%7D+make+this+%7Bcool%7Cawesome%7Crandom%7D+test+sentence+%7Brotate+%7Bquickly%7Cfast%7D+and+random%7Cspin+and+be+random%7D'
   18     1        ECHO                                                     !0
          2        ECHO                                                     '%0A'
          3        INIT_FCALL                                               'sentence_spinning'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $2      
          6        ECHO                                                     $2
          7      > RETURN                                                   1

Function sentence_spinning:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 2
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 2
Branch analysis from position: 16
Branch analysis from position: 2
filename:       /in/GLvim
function name:  sentence_spinning
number of ops:  18
compiled vars:  !0 = $str, !1 = $count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    7     1      > JMP                                                      ->11
    9     2    >   INIT_FCALL                                               'preg_replace_callback'
          3        SEND_VAL                                                 '%23%5C%7B%28%5B%5E%7B%7D%5D%2A%29%5C%7D%23'
          4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FGLvim%3A9%240'
   12     5        SEND_VAL                                                 ~2
          6        SEND_VAR                                                 !0
          7        SEND_VAL                                                 -1
          8        SEND_REF                                                 !1
          9        DO_ICALL                                         $3      
    9    10        ASSIGN                                                   !0, $3
    7    11    >   BEGIN_SILENCE                                    ~5      
         12        FETCH_R                      local               ~6      'count'
         13        END_SILENCE                                              ~5
         14        IS_NOT_IDENTICAL                                         ~6, 0
         15      > JMPNZ                                                    ~7, ->2
   15    16    > > RETURN                                                   !0
   16    17*     > RETURN                                                   null

End of function sentence_spinning

Function %00%7Bclosure%7D%2Fin%2FGLvim%3A9%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GLvim
function name:  {closure}
number of ops:  18
compiled vars:  !0 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   11     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '%7C'
          3        FETCH_DIM_R                                      ~1      !0, 1
          4        SEND_VAL                                                 ~1
          5        DO_ICALL                                         $2      
          6        INIT_FCALL                                               'mt_rand'
          7        SEND_VAL                                                 0
          8        INIT_FCALL                                               'substr_count'
          9        FETCH_DIM_R                                      ~3      !0, 1
         10        SEND_VAL                                                 ~3
         11        SEND_VAL                                                 '%7C'
         12        DO_ICALL                                         $4      
         13        SEND_VAR                                                 $4
         14        DO_ICALL                                         $5      
         15        FETCH_DIM_R                                      ~6      $2, $5
         16      > RETURN                                                   ~6
   12    17*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FGLvim%3A9%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.17 ms | 1403 KiB | 22 Q