3v4l.org

run code in 500+ PHP versions simultaneously
<?php $replaces = [ '#3d#' => '3D', '#\bmax\b#' => 'MAX', //меняем только вхождения в целых словах, слово max заменится на MAX, в слове maximum max не поднимется. '#program#is' => 'PROGRAM' //меняем любые вхождения: program, Program, PROgram и тд... получим PROGRAM ]; function replacer($params, $string) { $from = array_keys($params); $to = array_values($params); return preg_replace( $from, $to, $string); } $TheTitle = 'maximum best program for you - this is a 3d max - super puper pRoGrAm'; $titleNew = replacer($replaces, $TheTitle); var_dump($titleNew); //string(70) "maximum best PROGRAM for you - this is a 3D MAX - super puper PROGRAM"
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KlGKZ
function name:  (null)
number of ops:  11
compiled vars:  !0 = $replaces, !1 = $TheTitle, !2 = $titleNew
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   15     1        ASSIGN                                                       !1, 'maximum+best+program+for+you+-+this+is+a+3d+max+-+super++puper+pRoGrAm'
   17     2        INIT_FCALL                                                   'replacer'
          3        SEND_VAR                                                     !0
          4        SEND_VAR                                                     !1
          5        DO_FCALL                                          0  $5      
          6        ASSIGN                                                       !2, $5
   19     7        INIT_FCALL                                                   'var_dump'
          8        SEND_VAR                                                     !2
          9        DO_ICALL                                                     
         10      > RETURN                                                       1

Function replacer:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KlGKZ
function name:  replacer
number of ops:  14
compiled vars:  !0 = $params, !1 = $string, !2 = $from, !3 = $to
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    9     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   10     2        INIT_FCALL                                                   'array_keys'
          3        SEND_VAR                                                     !0
          4        DO_ICALL                                             $4      
          5        ASSIGN                                                       !2, $4
   11     6        INIT_FCALL                                                   'array_values'
          7        SEND_VAR                                                     !0
          8        DO_ICALL                                             $6      
          9        ASSIGN                                                       !3, $6
   12    10        FRAMELESS_ICALL_3                preg_replace        ~8      !2, !3
         11        OP_DATA                                                      !1
         12      > RETURN                                                       ~8
   13    13*     > RETURN                                                       null

End of function replacer

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
148.15 ms | 2052 KiB | 17 Q