3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Spintax { public static function Parse($text) { return self::Process($text); } private static function Process($text) { $pattern = '/\{(((?>[^\{\}]+)|(?R))*)\}/x'; return preg_replace_callback($pattern, ['Spintax', 'Replace'], $text); } private static function Replace($text) { $text = self::Process($text[1]); $parts = explode('|', $text); return $parts[array_rand($parts)]; } } $spintax = "{The|The actual|The particular|Your|This} breakthrough treatment {works by|functions|functions by|operates by|sticks to} oxygenating {the|the actual|the particular|your|this} blood {through an|with an|via an|using an|with the} injection {that can|that may|that will|which could|that could} hold {someone|somebody|an individual|a person|another person} alive {for up to|for approximately|for|for about|for as much as} 30 minutes {even if|even though|even when|regardless of whether|whether or not} they {are unable to|cannot|can't|can't seem to|are not able to} breath {at|from|with|in|on} everything {and could|and may|and might|and can|and may even} save {thousands of|a large number of|1000s of|a huge number of|many} lives."; for($n = 0; $n < 20; $n++){ echo Spintax::Parse($spintax) . "\n"; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 3
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 3
Branch analysis from position: 11
Branch analysis from position: 3
filename:       /in/IGWdi
function name:  (null)
number of ops:  12
compiled vars:  !0 = $spintax, !1 = $n
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   ASSIGN                                                   !0, '%7BThe%7CThe+actual%7CThe+particular%7CYour%7CThis%7D+breakthrough+treatment+%7Bworks+by%7Cfunctions%7Cfunctions+by%7Coperates+by%7Csticks+to%7D+oxygenating+%7Bthe%7Cthe+actual%7Cthe+particular%7Cyour%7Cthis%7D+blood+%7Bthrough+an%7Cwith+an%7Cvia+an%7Cusing+an%7Cwith+the%7D+injection+%7Bthat+can%7Cthat+may%7Cthat+will%7Cwhich+could%7Cthat+could%7D+hold+%7Bsomeone%7Csomebody%7Can+individual%7Ca+person%7Canother+person%7D+alive+%7Bfor+up+to%7Cfor+approximately%7Cfor%7Cfor+about%7Cfor+as+much+as%7D+30+minutes+%7Beven+if%7Ceven+though%7Ceven+when%7Cregardless+of+whether%7Cwhether+or+not%7D+they+%7Bare+unable+to%7Ccannot%7Ccan%27t%7Ccan%27t+seem+to%7Care+not+able+to%7D+breath+%7Bat%7Cfrom%7Cwith%7Cin%7Con%7D+everything+%7Band+could%7Cand+may%7Cand+might%7Cand+can%7Cand+may+even%7D+save+%7Bthousands+of%7Ca+large+number+of%7C1000s+of%7Ca+huge+number+of%7Cmany%7D+lives.'
   27     1        ASSIGN                                                   !1, 0
          2      > JMP                                                      ->9
   28     3    >   INIT_STATIC_METHOD_CALL                                  'Spintax', 'Parse'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $4      
          6        CONCAT                                           ~5      $4, '%0A'
          7        ECHO                                                     ~5
   27     8        PRE_INC                                                  !1
          9    >   IS_SMALLER                                               !1, 20
         10      > JMPNZ                                                    ~7, ->3
   29    11    > > RETURN                                                   1

Class Spintax:
Function parse:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IGWdi
function name:  Parse
number of ops:  6
compiled vars:  !0 = $text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    8     1        INIT_STATIC_METHOD_CALL                                  'Process'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $1      
          4      > RETURN                                                   $1
    9     5*     > RETURN                                                   null

End of function parse

Function process:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IGWdi
function name:  Process
number of ops:  9
compiled vars:  !0 = $text, !1 = $pattern
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   13     1        ASSIGN                                                   !1, '%2F%5C%7B%28%28%28%3F%3E%5B%5E%5C%7B%5C%7D%5D%2B%29%7C%28%3FR%29%29%2A%29%5C%7D%2Fx'
   14     2        INIT_FCALL                                               'preg_replace_callback'
          3        SEND_VAR                                                 !1
          4        SEND_VAL                                                 <array>
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $3      
          7      > RETURN                                                   $3
   15     8*     > RETURN                                                   null

End of function process

Function replace:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IGWdi
function name:  Replace
number of ops:  17
compiled vars:  !0 = $text, !1 = $parts
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   18     1        INIT_STATIC_METHOD_CALL                                  'Process'
          2        FETCH_DIM_R                                      ~2      !0, 1
          3        SEND_VAL                                                 ~2
          4        DO_FCALL                                      0  $3      
          5        ASSIGN                                                   !0, $3
   20     6        INIT_FCALL                                               'explode'
          7        SEND_VAL                                                 '%7C'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $5      
         10        ASSIGN                                                   !1, $5
   21    11        INIT_FCALL                                               'array_rand'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $7      
         14        FETCH_DIM_R                                      ~8      !1, $7
         15      > RETURN                                                   ~8
   22    16*     > RETURN                                                   null

End of function replace

End of class Spintax.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.07 ms | 1400 KiB | 19 Q