3v4l.org

run code in 500+ PHP versions simultaneously
<?php $html = <<<HTML Meet God's General Kathryn Kuhlman. <br> <img class="lazy_responsive" title="Kathryn Kuhlman - iUseFaith.com" src="https://www.iusefaith.com/ojm_thumbnail/1000/32f808f79011a7c0bd1ffefc1365c856.jpg" alt="Kathryn Kuhlman - iUseFaith.com" width="1600" height="517" /> <br> Follow <a href="https://www.iusefaith.com/en-354" title="Kathryn Kuhlman">Kathryn Kuhlman</a> <br> Max KANTCHEDE HTML; $keywords = [ 'Kathryn Kuhlman' => 'https://www.example.com/en-354', 'Max KANTCHEDE' => 'https://www.example.com/MaxKANTCHEDE', 'eneral' => 'https://www.example.com/this-is-not-used', ]; libxml_use_internal_errors(true); $dom = new DOMDocument(); $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $xpath = new DOMXPath($dom); $lookup = []; $regexNeedles = []; foreach ($keywords as $name => $link) { $lookup[strtolower($name)] = $link; $regexNeedles[] = preg_quote($name, '~'); } $pattern = '~\b(' . implode('|', $regexNeedles) . ')\b~i' ; foreach($xpath->query('//*[not(self::img or self::a)]/text()') as $textNode) { $newNodes = []; $hasReplacement = false; foreach (preg_split($pattern, $textNode->nodeValue, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $fragment) { $fragmentLower = strtolower($fragment); if (isset($lookup[$fragmentLower])) { $hasReplacement = true; $a = $dom->createElement('a'); $a->setAttribute('href', $lookup[$fragmentLower]); $a->setAttribute('title', $fragment); $a->nodeValue = $fragment; $newNodes[] = $a; } else { $newNodes[] = $dom->createTextNode($fragment); } } if ($hasReplacement) { $newFragment = $dom->createDocumentFragment(); foreach ($newNodes as $newNode) { $newFragment->appendChild($newNode); } $textNode->parentNode->replaceChild($newFragment, $textNode); } } echo substr(trim($dom->saveHTML()), 3, -4);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 33
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 33
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 33
2 jumps found. (Code = 77) Position 1 = 42, Position 2 = 104
Branch analysis from position: 42
2 jumps found. (Code = 78) Position 1 = 43, Position 2 = 104
Branch analysis from position: 43
2 jumps found. (Code = 77) Position 1 = 53, Position 2 = 86
Branch analysis from position: 53
2 jumps found. (Code = 78) Position 1 = 54, Position 2 = 86
Branch analysis from position: 54
2 jumps found. (Code = 43) Position 1 = 60, Position 2 = 80
Branch analysis from position: 60
1 jumps found. (Code = 42) Position 1 = 85
Branch analysis from position: 85
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
Branch analysis from position: 80
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
Branch analysis from position: 86
2 jumps found. (Code = 43) Position 1 = 88, Position 2 = 103
Branch analysis from position: 88
2 jumps found. (Code = 77) Position 1 = 92, Position 2 = 97
Branch analysis from position: 92
2 jumps found. (Code = 78) Position 1 = 93, Position 2 = 97
Branch analysis from position: 93
1 jumps found. (Code = 42) Position 1 = 92
Branch analysis from position: 92
Branch analysis from position: 97
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
Branch analysis from position: 97
Branch analysis from position: 103
Branch analysis from position: 86
Branch analysis from position: 104
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 104
Branch analysis from position: 33
filename:       /in/WUQ6k
function name:  (null)
number of ops:  112
compiled vars:  !0 = $html, !1 = $keywords, !2 = $dom, !3 = $xpath, !4 = $lookup, !5 = $regexNeedles, !6 = $link, !7 = $name, !8 = $pattern, !9 = $textNode, !10 = $newNodes, !11 = $hasReplacement, !12 = $fragment, !13 = $fragmentLower, !14 = $a, !15 = $newFragment, !16 = $newNode
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, 'Meet+God%27s+General+Kathryn+Kuhlman.+%3Cbr%3E%0A%3Cimg+class%3D%22lazy_responsive%22+title%3D%22Kathryn+Kuhlman+-+iUseFaith.com%22+src%3D%22https%3A%2F%2Fwww.iusefaith.com%2Fojm_thumbnail%2F1000%2F32f808f79011a7c0bd1ffefc1365c856.jpg%22+alt%3D%22Kathryn+Kuhlman+-+iUseFaith.com%22+width%3D%221600%22+height%3D%22517%22+%2F%3E%0A%3Cbr%3E%0AFollow+%3Ca+href%3D%22https%3A%2F%2Fwww.iusefaith.com%2Fen-354%22+title%3D%22Kathryn+Kuhlman%22%3EKathryn+Kuhlman%3C%2Fa%3E%0A%3Cbr%3E%0AMax+KANTCHEDE'
   12     1        ASSIGN                                                       !1, <array>
   18     2        INIT_FCALL                                                   'libxml_use_internal_errors'
          3        SEND_VAL                                                     <true>
          4        DO_ICALL                                                     
   19     5        NEW                                                  $20     'DOMDocument'
          6        DO_FCALL                                          0          
          7        ASSIGN                                                       !2, $20
   20     8        INIT_METHOD_CALL                                             !2, 'loadHTML'
          9        SEND_VAR_EX                                                  !0
         10        SEND_VAL_EX                                                  8196
         11        DO_FCALL                                          0          
   22    12        NEW                                                  $24     'DOMXPath'
         13        SEND_VAR_EX                                                  !2
         14        DO_FCALL                                          0          
         15        ASSIGN                                                       !3, $24
   24    16        ASSIGN                                                       !4, <array>
   25    17        ASSIGN                                                       !5, <array>
   26    18      > FE_RESET_R                                           $29     !1, ->33
         19    > > FE_FETCH_R                                           ~30     $29, !6, ->33
         20    >   ASSIGN                                                       !7, ~30
   27    21        INIT_FCALL                                                   'strtolower'
         22        SEND_VAR                                                     !7
         23        DO_ICALL                                             $32     
         24        ASSIGN_DIM                                                   !4, $32
         25        OP_DATA                                                      !6
   28    26        INIT_FCALL                                                   'preg_quote'
         27        SEND_VAR                                                     !7
         28        SEND_VAL                                                     '%7E'
         29        DO_ICALL                                             $35     
         30        ASSIGN_DIM                                                   !5
         31        OP_DATA                                                      $35
   26    32      > JMP                                                          ->19
         33    >   FE_FREE                                                      $29
   30    34        FRAMELESS_ICALL_2                implode             ~36     '%7C', !5
         35        CONCAT                                               ~37     '%7E%5Cb%28', ~36
         36        CONCAT                                               ~38     ~37, '%29%5Cb%7Ei'
         37        ASSIGN                                                       !8, ~38
   32    38        INIT_METHOD_CALL                                             !3, 'query'
         39        SEND_VAL_EX                                                  '%2F%2F%2A%5Bnot%28self%3A%3Aimg+or+self%3A%3Aa%29%5D%2Ftext%28%29'
         40        DO_FCALL                                          0  $40     
         41      > FE_RESET_R                                           $41     $40, ->104
         42    > > FE_FETCH_R                                                   $41, !9, ->104
   33    43    >   ASSIGN                                                       !10, <array>
   34    44        ASSIGN                                                       !11, <false>
   35    45        INIT_FCALL                                                   'preg_split'
         46        SEND_VAR                                                     !8
         47        FETCH_OBJ_R                                          ~44     !9, 'nodeValue'
         48        SEND_VAL                                                     ~44
         49        SEND_VAL                                                     0
         50        SEND_VAL                                                     3
         51        DO_ICALL                                             $45     
         52      > FE_RESET_R                                           $46     $45, ->86
         53    > > FE_FETCH_R                                                   $46, !12, ->86
   36    54    >   INIT_FCALL                                                   'strtolower'
         55        SEND_VAR                                                     !12
         56        DO_ICALL                                             $47     
         57        ASSIGN                                                       !13, $47
   37    58        ISSET_ISEMPTY_DIM_OBJ                             0          !4, !13
         59      > JMPZ                                                         ~49, ->80
   38    60    >   ASSIGN                                                       !11, <true>
   39    61        INIT_METHOD_CALL                                             !2, 'createElement'
         62        SEND_VAL_EX                                                  'a'
         63        DO_FCALL                                          0  $51     
         64        ASSIGN                                                       !14, $51
   40    65        INIT_METHOD_CALL                                             !14, 'setAttribute'
         66        SEND_VAL_EX                                                  'href'
         67        CHECK_FUNC_ARG                                               
         68        FETCH_DIM_FUNC_ARG                                   $53     !4, !13
         69        SEND_FUNC_ARG                                                $53
         70        DO_FCALL                                          0          
   41    71        INIT_METHOD_CALL                                             !14, 'setAttribute'
         72        SEND_VAL_EX                                                  'title'
         73        SEND_VAR_EX                                                  !12
         74        DO_FCALL                                          0          
   42    75        ASSIGN_OBJ                                                   !14, 'nodeValue'
         76        OP_DATA                                                      !12
   43    77        ASSIGN_DIM                                                   !10
         78        OP_DATA                                                      !14
   37    79      > JMP                                                          ->85
   45    80    >   INIT_METHOD_CALL                                             !2, 'createTextNode'
         81        SEND_VAR_EX                                                  !12
         82        DO_FCALL                                          0  $59     
         83        ASSIGN_DIM                                                   !10
         84        OP_DATA                                                      $59
   35    85    > > JMP                                                          ->53
         86    >   FE_FREE                                                      $46
   48    87      > JMPZ                                                         !11, ->103
   49    88    >   INIT_METHOD_CALL                                             !2, 'createDocumentFragment'
         89        DO_FCALL                                          0  $60     
         90        ASSIGN                                                       !15, $60
   50    91      > FE_RESET_R                                           $62     !10, ->97
         92    > > FE_FETCH_R                                                   $62, !16, ->97
   51    93    >   INIT_METHOD_CALL                                             !15, 'appendChild'
         94        SEND_VAR_EX                                                  !16
         95        DO_FCALL                                          0          
   50    96      > JMP                                                          ->92
         97    >   FE_FREE                                                      $62
   53    98        FETCH_OBJ_R                                          ~64     !9, 'parentNode'
         99        INIT_METHOD_CALL                                             ~64, 'replaceChild'
        100        SEND_VAR_EX                                                  !15
        101        SEND_VAR_EX                                                  !9
        102        DO_FCALL                                          0          
   32   103    > > JMP                                                          ->42
        104    >   FE_FREE                                                      $41
   56   105        INIT_METHOD_CALL                                             !2, 'saveHTML'
        106        DO_FCALL                                          0  $66     
        107        FRAMELESS_ICALL_1                trim                ~67     $66
        108        FRAMELESS_ICALL_3                substr              ~68     ~67, 3
        109        OP_DATA                                                      -4
        110        ECHO                                                         ~68
        111      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
209.63 ms | 2276 KiB | 23 Q