3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '{ "1": [ { "row": "My name is Trevor\n" }, { "row": "Can you see me?\n" }, { "row": "\f" } ], "2": [ { "row": "Hey there! Some other text.\n" }, { "row": "What is up Trevor?\n" }, { "row": "\f" } ], "3": [ { "row": "Some text on the third column. First row." }, { "row": "\f" } ] }'; $content = json_decode($json, true); class regexTextReplace { private $pattern; private $replacement; public function __construct(array $arguments) { $this->pattern = $arguments['pattern']; $this->replacement = $arguments['replacement']; } public function apply(array $table, $column = false): array { $table = $column ? $table[$column] : $table; return array_map('self::regex_replace', $table); } public function regex_replace(array $table) { return preg_replace($this->pattern, $this->replacement, $table); } } $options = [ 'pattern' => '/Trevor/i', 'replacement' => 'Oliver', ]; $engine = new regexTextReplace($options); foreach($content as $key => $v){ $columns[$key] = $engine->apply($content, $key); } var_dump($columns);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 21
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 21
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/Pk2rC
function name:  (null)
number of ops:  26
compiled vars:  !0 = $json, !1 = $content, !2 = $options, !3 = $engine, !4 = $v, !5 = $key, !6 = $columns
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%7B%0A++++%221%22%3A+%5B%0A++++++++%7B%0A++++++++++++%22row%22%3A+%22My+name+is+Trevor%5Cn%22%0A++++++++%7D%2C%0A++++++++%7B%0A++++++++++++%22row%22%3A+%22Can+you+see+me%3F%5Cn%22%0A++++++++%7D%2C%0A++++++++%7B%0A++++++++++++%22row%22%3A+%22%5Cf%22%0A++++++++%7D%0A++++%5D%2C%0A++++%222%22%3A+%5B%0A++++++++%7B%0A++++++++++++%22row%22%3A+%22Hey+there%21+Some+other+text.%5Cn%22%0A++++++++%7D%2C%0A++++++++%7B%0A++++++++++++%22row%22%3A+%22What+is+up+Trevor%3F%5Cn%22%0A++++++++%7D%2C%0A++++++++%7B%0A++++++++++++%22row%22%3A+%22%5Cf%22%0A++++++++%7D%0A++++%5D%2C%0A++++%223%22%3A+%5B%0A++++++++%7B%0A++++++++++++%22row%22%3A+%22Some+text+on+the+third+column.+First+row.%22%0A++++++++%7D%2C%0A++++++++%7B%0A++++++++++++%22row%22%3A+%22%5Cf%22%0A++++++++%7D%0A++++%5D%0A%7D'
   35     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $8      
          5        ASSIGN                                                   !1, $8
   61     6        ASSIGN                                                   !2, <array>
   65     7        NEW                                              $11     'regexTextReplace'
          8        SEND_VAR_EX                                              !2
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !3, $11
   66    11      > FE_RESET_R                                       $14     !1, ->21
         12    > > FE_FETCH_R                                       ~15     $14, !4, ->21
         13    >   ASSIGN                                                   !5, ~15
   67    14        INIT_METHOD_CALL                                         !3, 'apply'
         15        SEND_VAR_EX                                              !1
         16        SEND_VAR_EX                                              !5
         17        DO_FCALL                                      0  $18     
         18        ASSIGN_DIM                                               !6, !5
         19        OP_DATA                                                  $18
   66    20      > JMP                                                      ->12
         21    >   FE_FREE                                                  $14
   69    22        INIT_FCALL                                               'var_dump'
         23        SEND_VAR                                                 !6
         24        DO_ICALL                                                 
         25      > RETURN                                                   1

Class regexTextReplace:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Pk2rC
function name:  __construct
number of ops:  8
compiled vars:  !0 = $arguments
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   RECV                                             !0      
   44     1        FETCH_DIM_R                                      ~2      !0, 'pattern'
          2        ASSIGN_OBJ                                               'pattern'
          3        OP_DATA                                                  ~2
   45     4        FETCH_DIM_R                                      ~4      !0, 'replacement'
          5        ASSIGN_OBJ                                               'replacement'
          6        OP_DATA                                                  ~4
   46     7      > RETURN                                                   null

End of function __construct

Function apply:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 6
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Pk2rC
function name:  apply
number of ops:  16
compiled vars:  !0 = $table, !1 = $column
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <false>
   50     2      > JMPZ                                                     !1, ->6
          3    >   FETCH_DIM_R                                      ~2      !0, !1
          4        QM_ASSIGN                                        ~3      ~2
          5      > JMP                                                      ->7
          6    >   QM_ASSIGN                                        ~3      !0
          7    >   ASSIGN                                                   !0, ~3
   52     8        INIT_FCALL                                               'array_map'
          9        SEND_VAL                                                 'self%3A%3Aregex_replace'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $5      
         12        VERIFY_RETURN_TYPE                                       $5
         13      > RETURN                                                   $5
   53    14*       VERIFY_RETURN_TYPE                                       
         15*     > RETURN                                                   null

End of function apply

Function regex_replace:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Pk2rC
function name:  regex_replace
number of ops:  10
compiled vars:  !0 = $table
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   RECV                                             !0      
   57     1        INIT_FCALL                                               'preg_replace'
          2        FETCH_OBJ_R                                      ~1      'pattern'
          3        SEND_VAL                                                 ~1
          4        FETCH_OBJ_R                                      ~2      'replacement'
          5        SEND_VAL                                                 ~2
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $3      
          8      > RETURN                                                   $3
   58     9*     > RETURN                                                   null

End of function regex_replace

End of class regexTextReplace.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.14 ms | 1400 KiB | 21 Q