3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = "<p>Just a test: getName testName</p>"; $keywords = [ 0=>['id'=>1,'slug'=>'getName','url'=>'https://www.getname.com'], 1=>['id'=>2,'slug'=>'testName','url'=>'https://www.testname.com'], 2=>['id'=>3,'slug'=>'ign','url'=>'https://www.ign.com'] ]; $newKeywords = []; foreach ($keywords as $keyword) $newKeywords[$keyword['slug']] = $keyword['url']; $newStr = preg_replace_callback("/(\w+)/", function($m) use($newKeywords){ return isset($newKeywords[$m[0]]) ? "<a href='{$newKeywords[$m[0]]}'>{$m[0]}</a>" : $m[0]; }, $str); echo $newStr;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/ev7V1
function name:  (null)
number of ops:  21
compiled vars:  !0 = $str, !1 = $keywords, !2 = $newKeywords, !3 = $keyword, !4 = $newStr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Cp%3EJust+a+test%3A+getName++testName%3C%2Fp%3E'
    4     1        ASSIGN                                                   !1, <array>
   10     2        ASSIGN                                                   !2, <array>
   11     3      > FE_RESET_R                                       $8      !1, ->10
          4    > > FE_FETCH_R                                               $8, !3, ->10
   12     5    >   FETCH_DIM_R                                      ~9      !3, 'slug'
          6        FETCH_DIM_R                                      ~11     !3, 'url'
          7        ASSIGN_DIM                                               !2, ~9
          8        OP_DATA                                                  ~11
   11     9      > JMP                                                      ->4
         10    >   FE_FREE                                                  $8
   14    11        INIT_FCALL                                               'preg_replace_callback'
         12        SEND_VAL                                                 '%2F%28%5Cw%2B%29%2F'
         13        DECLARE_LAMBDA_FUNCTION                          ~12     [0]
         14        BIND_LEXICAL                                             ~12, !2
   16    15        SEND_VAL                                                 ~12
         16        SEND_VAR                                                 !0
   14    17        DO_ICALL                                         $13     
         18        ASSIGN                                                   !4, $13
   18    19        ECHO                                                     !4
   19    20      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 15
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ev7V1
function name:  {closure}
number of ops:  19
compiled vars:  !0 = $m, !1 = $newKeywords
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   15     2        FETCH_DIM_R                                      ~2      !0, 0
          3        ISSET_ISEMPTY_DIM_OBJ                         0          !1, ~2
          4      > JMPZ                                                     ~3, ->15
          5    >   ROPE_INIT                                     5  ~8      '%3Ca+href%3D%27'
          6        FETCH_DIM_R                                      ~4      !0, 0
          7        FETCH_DIM_R                                      ~5      !1, ~4
          8        ROPE_ADD                                      1  ~8      ~8, ~5
          9        ROPE_ADD                                      2  ~8      ~8, '%27%3E'
         10        FETCH_DIM_R                                      ~6      !0, 0
         11        ROPE_ADD                                      3  ~8      ~8, ~6
         12        ROPE_END                                      4  ~7      ~8, '%3C%2Fa%3E'
         13        QM_ASSIGN                                        ~11     ~7
         14      > JMP                                                      ->17
         15    >   FETCH_DIM_R                                      ~12     !0, 0
         16        QM_ASSIGN                                        ~11     ~12
         17    > > RETURN                                                   ~11
   16    18*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.49 ms | 1441 KiB | 14 Q