3v4l.org

run code in 300+ PHP versions simultaneously
<?php function translatePronouns($text) { static $replacePairs = [ 'iyou' => ['i', 'you'], 'youi' => ['^you', 'i'], 'myyour' => ['my', 'your'], 'yourmy' => ['your', 'my'], 'meyou' => ['me', 'you'], 'youme' => ['you', 'me'], 'myselfyourself' => ['myself', 'yourself'], 'yourselfmyself' => ['yourself', 'myself'], 'mineyours' => ['mine', 'yours'], 'yoursmine' => ['yours', 'mine'], ]; static $expr; if (!isset($expr)) { $parts = []; foreach ($replacePairs as $name => $pair) { $parts[] = "(?<=^|\s)(?P<$name>$pair[0])(?=$|\s)"; } $expr = '#' . implode('|', $parts) . '#i'; } return preg_replace_callback($expr, function($match) use($replacePairs) { foreach ($match as $name => $text) { if ($text !== '' && isset($replacePairs[$name])) { return $replacePairs[$name][1]; } } // var_dump($match); //return $replacePairs[$match[0]]; }, $text); } $strings = [ 'i should go fuck myself', 'i will kill you if i decide it suits me to do so', 'you will eat me', 'my boobs are bigger than yours' ]; foreach ($strings as $string) { echo translatePronouns($string) . "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 9
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/fUQW9
function name:  (null)
number of ops:  11
compiled vars:  !0 = $strings, !1 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   ASSIGN                                                   !0, <array>
   47     1      > FE_RESET_R                                       $3      !0, ->9
          2    > > FE_FETCH_R                                               $3, !1, ->9
   48     3    >   INIT_FCALL                                               'translatepronouns'
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $4      
          6        CONCAT                                           ~5      $4, '%0A'
          7        ECHO                                                     ~5
   47     8      > JMP                                                      ->2
          9    >   FE_FREE                                                  $3
   49    10      > RETURN                                                   1

Function translatepronouns:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 27
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 19
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 19
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
Branch analysis from position: 27
filename:       /in/fUQW9
function name:  translatePronouns
number of ops:  36
compiled vars:  !0 = $text, !1 = $replacePairs, !2 = $expr, !3 = $parts, !4 = $pair, !5 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        BIND_STATIC                                              !1
   17     2        BIND_STATIC                                              !2
   19     3        ISSET_ISEMPTY_CV                                 ~6      !2
          4        BOOL_NOT                                         ~7      ~6
          5      > JMPZ                                                     ~7, ->27
   20     6    >   ASSIGN                                                   !3, <array>
   22     7      > FE_RESET_R                                       $9      !1, ->19
          8    > > FE_FETCH_R                                       ~10     $9, !4, ->19
          9    >   ASSIGN                                                   !5, ~10
   23    10        ROPE_INIT                                     5  ~15     '%28%3F%3C%3D%5E%7C%5Cs%29%28%3FP%3C'
         11        ROPE_ADD                                      1  ~15     ~15, !5
         12        ROPE_ADD                                      2  ~15     ~15, '%3E'
         13        FETCH_DIM_R                                      ~13     !4, 0
         14        ROPE_ADD                                      3  ~15     ~15, ~13
         15        ROPE_END                                      4  ~14     ~15, '%29%28%3F%3D%24%7C%5Cs%29'
         16        ASSIGN_DIM                                               !3
         17        OP_DATA                                                  ~14
   22    18      > JMP                                                      ->8
         19    >   FE_FREE                                                  $9
   26    20        INIT_FCALL                                               'implode'
         21        SEND_VAL                                                 '%7C'
         22        SEND_VAR                                                 !3
         23        DO_ICALL                                         $18     
         24        CONCAT                                           ~19     '%23', $18
         25        CONCAT                                           ~20     ~19, '%23i'
         26        ASSIGN                                                   !2, ~20
   29    27    >   INIT_FCALL                                               'preg_replace_callback'
         28        SEND_VAR                                                 !2
         29        DECLARE_LAMBDA_FUNCTION                          ~22     [0]
         30        BIND_LEXICAL                                             ~22, !1
   37    31        SEND_VAL                                                 ~22
         32        SEND_VAR                                                 !0
   29    33        DO_ICALL                                         $23     
   37    34      > RETURN                                                   $23
   38    35*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 15
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 15
Branch analysis from position: 4
2 jumps found. (Code = 46) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 14
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 9
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/fUQW9
function name:  {closure}
number of ops:  17
compiled vars:  !0 = $match, !1 = $replacePairs, !2 = $text, !3 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   30     2      > FE_RESET_R                                       $4      !0, ->15
          3    > > FE_FETCH_R                                       ~5      $4, !2, ->15
          4    >   ASSIGN                                                   !3, ~5
   31     5        IS_NOT_IDENTICAL                                 ~7      !2, ''
          6      > JMPZ_EX                                          ~7      ~7, ->9
          7    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~8      !1, !3
          8        BOOL                                             ~7      ~8
          9    > > JMPZ                                                     ~7, ->14
   32    10    >   FETCH_DIM_R                                      ~9      !1, !3
         11        FETCH_DIM_R                                      ~10     ~9, 1
         12        FE_FREE                                                  $4
         13      > RETURN                                                   ~10
   30    14    > > JMP                                                      ->3
         15    >   FE_FREE                                                  $4
   37    16      > RETURN                                                   null

End of Dynamic Function 0

End of function translatepronouns

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.73 ms | 1010 KiB | 16 Q