3v4l.org

run code in 300+ PHP versions simultaneously
<?php $strings = [ "<p>We've been in business since 1998 and produced this logo design [2002] years ago.</p>", "<p>We've been in business since 1998 and produced this logo design [2017] years ago.</p>" ]; foreach ($strings as $string) { preg_match('/\[(\d{4})\] years/', $string, $matches); $years = date('Y') - $matches[1]; $result = sprintf("%s year%s", $years, $years === 1 ? "": "s" ); echo str_replace($matches[0], $result, $string) . PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 34
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 34
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/DLqUh
function name:  (null)
number of ops:  36
compiled vars:  !0 = $strings, !1 = $string, !2 = $matches, !3 = $years, !4 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    8     1      > FE_RESET_R                                       $6      !0, ->34
          2    > > FE_FETCH_R                                               $6, !1, ->34
    9     3    >   INIT_FCALL                                               'preg_match'
          4        SEND_VAL                                                 '%2F%5C%5B%28%5Cd%7B4%7D%29%5C%5D+years%2F'
          5        SEND_VAR                                                 !1
          6        SEND_REF                                                 !2
          7        DO_ICALL                                                 
   10     8        INIT_FCALL                                               'date'
          9        SEND_VAL                                                 'Y'
         10        DO_ICALL                                         $8      
         11        FETCH_DIM_R                                      ~9      !2, 1
         12        SUB                                              ~10     $8, ~9
         13        ASSIGN                                                   !3, ~10
   11    14        INIT_FCALL                                               'sprintf'
         15        SEND_VAL                                                 '%25s+year%25s'
   12    16        SEND_VAR                                                 !3
   13    17        IS_IDENTICAL                                             !3, 1
         18      > JMPZ                                                     ~12, ->21
         19    >   QM_ASSIGN                                        ~13     ''
         20      > JMP                                                      ->22
         21    >   QM_ASSIGN                                        ~13     's'
         22    >   SEND_VAL                                                 ~13
   11    23        DO_ICALL                                         $14     
         24        ASSIGN                                                   !4, $14
   15    25        INIT_FCALL                                               'str_replace'
         26        FETCH_DIM_R                                      ~16     !2, 0
         27        SEND_VAL                                                 ~16
         28        SEND_VAR                                                 !4
         29        SEND_VAR                                                 !1
         30        DO_ICALL                                         $17     
         31        CONCAT                                           ~18     $17, '%0A'
         32        ECHO                                                     ~18
    8    33      > JMP                                                      ->2
         34    >   FE_FREE                                                  $6
   16    35      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
270.66 ms | 1074 KiB | 17 Q