3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "Red Cell is very good. Condition is new. But nobody buys it."; $words = ["Red Cell", "Condition", "no", "Red", "new"]; $translations = ["Red Cell", "Stav", "ne", "Červený", "nový"]; $pairs = array_combine($words, $translations); krsort($pairs); $pattern = '~\b(?:' . implode('|', array_keys($pairs)) . ')\b~u'; $result = preg_replace_callback($pattern, function ($m) use ($pairs) { return $pairs[$m[0]]; }, $string); echo $result;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EgrVV
function name:  (null)
number of ops:  31
compiled vars:  !0 = $string, !1 = $words, !2 = $translations, !3 = $pairs, !4 = $pattern, !5 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'Red+Cell+is+very+good.+Condition+is+new.+But+nobody+buys+it.'
    4     1        ASSIGN                                                   !1, <array>
    5     2        ASSIGN                                                   !2, <array>
    7     3        INIT_FCALL                                               'array_combine'
          4        SEND_VAR                                                 !1
          5        SEND_VAR                                                 !2
          6        DO_ICALL                                         $9      
          7        ASSIGN                                                   !3, $9
    8     8        INIT_FCALL                                               'krsort'
          9        SEND_REF                                                 !3
         10        DO_ICALL                                                 
   10    11        INIT_FCALL                                               'implode'
         12        SEND_VAL                                                 '%7C'
         13        INIT_FCALL                                               'array_keys'
         14        SEND_VAR                                                 !3
         15        DO_ICALL                                         $12     
         16        SEND_VAR                                                 $12
         17        DO_ICALL                                         $13     
         18        CONCAT                                           ~14     '%7E%5Cb%28%3F%3A', $13
         19        CONCAT                                           ~15     ~14, '%29%5Cb%7Eu'
         20        ASSIGN                                                   !4, ~15
   12    21        INIT_FCALL                                               'preg_replace_callback'
         22        SEND_VAR                                                 !4
         23        DECLARE_LAMBDA_FUNCTION                          ~17     [0]
         24        BIND_LEXICAL                                             ~17, !3
         25        SEND_VAL                                                 ~17
         26        SEND_VAR                                                 !0
         27        DO_ICALL                                         $18     
         28        ASSIGN                                                   !5, $18
   14    29        ECHO                                                     !5
   15    30      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EgrVV
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $m, !1 = $pairs
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        FETCH_DIM_R                                      ~2      !0, 0
          3        FETCH_DIM_R                                      ~3      !1, ~2
          4      > RETURN                                                   ~3
          5*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.65 ms | 1010 KiB | 18 Q