3v4l.org

run code in 300+ PHP versions simultaneously
<?php $colours = array("Red", "Blue", "Green"); $string = "There are three Red and Green walls."; echo preg_replace("/" . implode("|", array_map(function($i) {return preg_quote($i, "/");}, $colours)) . "/", '%1%$0%2%', $string); echo "\n" . preg_replace("/\b(?:" . implode('|', $colours) . ")\b/", '%1%$0%2%', $string); $colours = array("Red", "Blue", "Green", "Blue jeans"); $string = "There are three Red and Green walls and Blue jeans."; rsort($colours, SORT_FLAG_CASE | SORT_STRING); echo "\n" . preg_replace("/" . implode("|", array_map(function($i) {return preg_quote($i, "/");}, $colours)) . "/", '%1%$0%2%',$string);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UpspN
function name:  (null)
number of ops:  57
compiled vars:  !0 = $colours, !1 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, 'There+are+three+Red+and+Green+walls.'
    6     2        INIT_FCALL                                               'preg_replace'
          3        INIT_FCALL                                               'implode'
          4        SEND_VAL                                                 '%7C'
          5        INIT_FCALL                                               'array_map'
          6        DECLARE_LAMBDA_FUNCTION                          ~4      [0]
          7        SEND_VAL                                                 ~4
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $5      
         10        SEND_VAR                                                 $5
         11        DO_ICALL                                         $6      
         12        CONCAT                                           ~7      '%2F', $6
         13        CONCAT                                           ~8      ~7, '%2F'
         14        SEND_VAL                                                 ~8
         15        SEND_VAL                                                 '%251%25%240%252%25'
         16        SEND_VAR                                                 !1
         17        DO_ICALL                                         $9      
         18        ECHO                                                     $9
    7    19        INIT_FCALL                                               'preg_replace'
         20        INIT_FCALL                                               'implode'
         21        SEND_VAL                                                 '%7C'
         22        SEND_VAR                                                 !0
         23        DO_ICALL                                         $10     
         24        CONCAT                                           ~11     '%2F%5Cb%28%3F%3A', $10
         25        CONCAT                                           ~12     ~11, '%29%5Cb%2F'
         26        SEND_VAL                                                 ~12
         27        SEND_VAL                                                 '%251%25%240%252%25'
         28        SEND_VAR                                                 !1
         29        DO_ICALL                                         $13     
         30        CONCAT                                           ~14     '%0A', $13
         31        ECHO                                                     ~14
    9    32        ASSIGN                                                   !0, <array>
   10    33        ASSIGN                                                   !1, 'There+are+three+Red+and+Green+walls+and+Blue+jeans.'
   11    34        INIT_FCALL                                               'rsort'
         35        SEND_REF                                                 !0
         36        SEND_VAL                                                 10
         37        DO_ICALL                                                 
   13    38        INIT_FCALL                                               'preg_replace'
         39        INIT_FCALL                                               'implode'
         40        SEND_VAL                                                 '%7C'
         41        INIT_FCALL                                               'array_map'
         42        DECLARE_LAMBDA_FUNCTION                          ~18     [1]
         43        SEND_VAL                                                 ~18
         44        SEND_VAR                                                 !0
         45        DO_ICALL                                         $19     
         46        SEND_VAR                                                 $19
         47        DO_ICALL                                         $20     
         48        CONCAT                                           ~21     '%2F', $20
         49        CONCAT                                           ~22     ~21, '%2F'
         50        SEND_VAL                                                 ~22
         51        SEND_VAL                                                 '%251%25%240%252%25'
         52        SEND_VAR                                                 !1
         53        DO_ICALL                                         $23     
         54        CONCAT                                           ~24     '%0A', $23
         55        ECHO                                                     ~24
         56      > 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/UpspN
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        INIT_FCALL                                               'preg_quote'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 '%2F'
          4        DO_ICALL                                         $1      
          5      > RETURN                                                   $1
          6*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UpspN
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        INIT_FCALL                                               'preg_quote'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 '%2F'
          4        DO_ICALL                                         $1      
          5      > RETURN                                                   $1
          6*     > RETURN                                                   null

End of Dynamic Function 1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.98 ms | 1019 KiB | 18 Q