3v4l.org

run code in 300+ PHP versions simultaneously
<?PHP /** * Spintax - A helper class to process Spintax strings. * @name Spintax * @author Jason Davis - http://www.codedevelopr.com/ */ class Spintax { public function process($text) { return preg_replace_callback( '/\{(((?>[^\{\}]+)|(?R))*)\}/x', array($this, 'replace'), $text ); } public function replace($text) { $text = $this->process($text[1]); $parts = explode('|', $text); return $parts[array_rand($parts)]; } } ?> <?PHP $spintax = new Spintax(); $string = '{Hello|Howdy|Hola} to you, {Mr.|Mrs.|Ms.} {Smith|Williams|Davis}!'; echo $spintax->process($string); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mXbIs
function name:  (null)
number of ops:  10
compiled vars:  !0 = $spintax, !1 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   ECHO                                                     '%0A'
   28     1        NEW                                              $2      'Spintax'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $2
   29     4        ASSIGN                                                   !1, '%7BHello%7CHowdy%7CHola%7D+to+you%2C+%7BMr.%7CMrs.%7CMs.%7D+%7BSmith%7CWilliams%7CDavis%7D%21'
   30     5        INIT_METHOD_CALL                                         !0, 'process'
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0  $6      
          8        ECHO                                                     $6
   31     9      > RETURN                                                   1

Class Spintax:
Function process:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mXbIs
function name:  process
number of ops:  11
compiled vars:  !0 = $text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   11     1        INIT_FCALL                                               'preg_replace_callback'
   12     2        SEND_VAL                                                 '%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'
   13     3        FETCH_THIS                                       ~1      
          4        INIT_ARRAY                                       ~2      ~1
          5        ADD_ARRAY_ELEMENT                                ~2      'replace'
          6        SEND_VAL                                                 ~2
   14     7        SEND_VAR                                                 !0
   11     8        DO_ICALL                                         $3      
   14     9      > RETURN                                                   $3
   16    10*     > 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/mXbIs
function name:  replace
number of ops:  18
compiled vars:  !0 = $text, !1 = $parts
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   20     1        INIT_METHOD_CALL                                         'process'
          2        CHECK_FUNC_ARG                                           
          3        FETCH_DIM_FUNC_ARG                               $2      !0, 1
          4        SEND_FUNC_ARG                                            $2
          5        DO_FCALL                                      0  $3      
          6        ASSIGN                                                   !0, $3
   21     7        INIT_FCALL                                               'explode'
          8        SEND_VAL                                                 '%7C'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                         $5      
         11        ASSIGN                                                   !1, $5
   22    12        INIT_FCALL                                               'array_rand'
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                         $7      
         15        FETCH_DIM_R                                      ~8      !1, $7
         16      > RETURN                                                   ~8
   23    17*     > RETURN                                                   null

End of function replace

End of class Spintax.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.49 ms | 1012 KiB | 16 Q