3v4l.org

run code in 300+ PHP versions simultaneously
<? $data = "The cat likes to sit on the fence. He also likes to climb the tree."; $find ="/the/"; $replace ="a"; //1. replace single word Echo "$data <br>"; Echo preg_replace ($find, $replace, $data); //create arrays $find2 = array ('/the/', '/cat/'); $replace2 = array ('a', 'dog'); //2. replace with array values Echo preg_replace ($find2, $replace2, $data); //3. Replace just once Echo preg_replace ($find2, $replace2, $data, 1); //4. Keep a count of replacements $count = 0; Echo preg_replace ($find2, $replace2, $data, -1, $count); Echo "<br>You have made $count replacements"; ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZaXsh
function name:  (null)
number of ops:  41
compiled vars:  !0 = $data, !1 = $find, !2 = $replace, !3 = $find2, !4 = $replace2, !5 = $count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'The+cat+likes+to+sit+on+the+fence.+He+also+likes+to+climb+the+tree.'
    4     1        ASSIGN                                                   !1, '%2Fthe%2F'
    5     2        ASSIGN                                                   !2, 'a'
    8     3        NOP                                                      
          4        FAST_CONCAT                                      ~9      !0, '+%3Cbr%3E'
          5        ECHO                                                     ~9
    9     6        INIT_FCALL                                               'preg_replace'
          7        SEND_VAR                                                 !1
          8        SEND_VAR                                                 !2
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                         $10     
         11        ECHO                                                     $10
   12    12        ASSIGN                                                   !3, <array>
   13    13        ASSIGN                                                   !4, <array>
   16    14        INIT_FCALL                                               'preg_replace'
         15        SEND_VAR                                                 !3
         16        SEND_VAR                                                 !4
         17        SEND_VAR                                                 !0
         18        DO_ICALL                                         $13     
         19        ECHO                                                     $13
   19    20        INIT_FCALL                                               'preg_replace'
         21        SEND_VAR                                                 !3
         22        SEND_VAR                                                 !4
         23        SEND_VAR                                                 !0
         24        SEND_VAL                                                 1
         25        DO_ICALL                                         $14     
         26        ECHO                                                     $14
   22    27        ASSIGN                                                   !5, 0
   23    28        INIT_FCALL                                               'preg_replace'
         29        SEND_VAR                                                 !3
         30        SEND_VAR                                                 !4
         31        SEND_VAR                                                 !0
         32        SEND_VAL                                                 -1
         33        SEND_REF                                                 !5
         34        DO_ICALL                                         $16     
         35        ECHO                                                     $16
   24    36        ROPE_INIT                                     3  ~18     '%3Cbr%3EYou+have+made+'
         37        ROPE_ADD                                      1  ~18     ~18, !5
         38        ROPE_END                                      2  ~17     ~18, '+replacements'
         39        ECHO                                                     ~17
   26    40      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.97 ms | 1396 KiB | 15 Q