3v4l.org

run code in 500+ 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:  28
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                                                   'array_keys'
         12        SEND_VAR                                                     !3
         13        DO_ICALL                                             $12     
         14        FRAMELESS_ICALL_2                implode             ~13     '%7C', $12
         15        CONCAT                                               ~14     '%7E%5Cb%28%3F%3A', ~13
         16        CONCAT                                               ~15     ~14, '%29%5Cb%7Eu'
         17        ASSIGN                                                       !4, ~15
   12    18        INIT_FCALL                                                   'preg_replace_callback'
         19        SEND_VAR                                                     !4
         20        DECLARE_LAMBDA_FUNCTION                              ~17     [0]
         21        BIND_LEXICAL                                                 ~17, !3
         22        SEND_VAL                                                     ~17
         23        SEND_VAR                                                     !0
         24        DO_ICALL                                             $18     
         25        ASSIGN                                                       !5, $18
   14    26        ECHO                                                         !5
   15    27      > 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:/in/EgrVV:12}
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.5.0


preferences:
223.04 ms | 2298 KiB | 17 Q