3v4l.org

run code in 300+ PHP versions simultaneously
<?php $keywords = [ 'keywords' => 'www.1.com', 'hello' => 'www.2.com', 'there' => 'www.3.com', 'are' => 'www.4.com', ]; $sentence = ' <div> <h1>Hello</h1> <h2>Hello there blablabla</h2> <p>Hello, there are keywords</p> <p>Hello, there are keywords</p> <p>Hello, there are keywords</p> <p>Hello, there are keywords</p> <p>Hello, there are keywords</p> </div>'; $dom = new DOMDocument; $dom->loadHTML($sentence, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); foreach ($dom->getElementsByTagName('p') as $p) { $p->nodeValue = preg_replace_callback( '~\b(?:' . implode('|', array_keys($keywords)) . ')\b~i', function($m) use ($keywords) { return $keywords[strtolower($m[0])]; }, $p->nodeValue ); } echo $dom->saveHTML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 34
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 34
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/Qdl34
function name:  (null)
number of ops:  39
compiled vars:  !0 = $keywords, !1 = $sentence, !2 = $dom, !3 = $p
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   10     1        ASSIGN                                                   !1, '%0A%3Cdiv%3E%0A++++%3Ch1%3EHello%3C%2Fh1%3E%0A++++%3Ch2%3EHello+there+blablabla%3C%2Fh2%3E%0A++++%3Cp%3EHello%2C+there+are+keywords%3C%2Fp%3E%0A++++%3Cp%3EHello%2C+there+are+keywords%3C%2Fp%3E%0A++++%3Cp%3EHello%2C+there+are+keywords%3C%2Fp%3E%0A++++%3Cp%3EHello%2C+there+are+keywords%3C%2Fp%3E%0A++++%3Cp%3EHello%2C+there+are+keywords%3C%2Fp%3E%0A%3C%2Fdiv%3E'
   21     2        NEW                                              $6      'DOMDocument'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !2, $6
   22     5        INIT_METHOD_CALL                                         !2, 'loadHTML'
          6        SEND_VAR_EX                                              !1
          7        SEND_VAL_EX                                              8196
          8        DO_FCALL                                      0          
   23     9        INIT_METHOD_CALL                                         !2, 'getElementsByTagName'
         10        SEND_VAL_EX                                              'p'
         11        DO_FCALL                                      0  $10     
         12      > FE_RESET_R                                       $11     $10, ->34
         13    > > FE_FETCH_R                                               $11, !3, ->34
   24    14    >   INIT_FCALL                                               'preg_replace_callback'
   25    15        INIT_FCALL                                               'implode'
         16        SEND_VAL                                                 '%7C'
         17        INIT_FCALL                                               'array_keys'
         18        SEND_VAR                                                 !0
         19        DO_ICALL                                         $13     
         20        SEND_VAR                                                 $13
         21        DO_ICALL                                         $14     
         22        CONCAT                                           ~15     '%7E%5Cb%28%3F%3A', $14
         23        CONCAT                                           ~16     ~15, '%29%5Cb%7Ei'
         24        SEND_VAL                                                 ~16
   26    25        DECLARE_LAMBDA_FUNCTION                          ~17     [0]
         26        BIND_LEXICAL                                             ~17, !0
   28    27        SEND_VAL                                                 ~17
   29    28        FETCH_OBJ_R                                      ~18     !3, 'nodeValue'
         29        SEND_VAL                                                 ~18
   24    30        DO_ICALL                                         $19     
         31        ASSIGN_OBJ                                               !3, 'nodeValue'
   29    32        OP_DATA                                                  $19
   23    33      > JMP                                                      ->13
         34    >   FE_FREE                                                  $11
   32    35        INIT_METHOD_CALL                                         !2, 'saveHTML'
         36        DO_FCALL                                      0  $20     
         37        ECHO                                                     $20
         38      > 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/Qdl34
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $m, !1 = $keywords
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   27     2        INIT_FCALL                                               'strtolower'
          3        FETCH_DIM_R                                      ~2      !0, 0
          4        SEND_VAL                                                 ~2
          5        DO_ICALL                                         $3      
          6        FETCH_DIM_R                                      ~4      !1, $3
          7      > RETURN                                                   ~4
   28     8*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.6 ms | 1018 KiB | 17 Q