3v4l.org

run code in 300+ 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:  17
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        INIT_FCALL                                               'preg_replace'
         11        SEND_VAR                                                 !2
         12        SEND_VAR                                                 !3
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                         $8      
         15      > RETURN                                                   $8
   13    16*     > RETURN                                                   null

End of function replacer

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.43 ms | 1006 KiB | 18 Q