3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = 'This is a text with multiple anchor tags. This is the first one: <a href="https://www.link1.com/" title="Link 1">Link 1</a> and this one the second: <a href="https://www.link2.com/" title="Link 2">Link 2</a> after that a lot of other text. And here the 3rd one: <a href="https://www.link3.com/" title="Link 3">Link 3</a> Some other text.'; $dom = new DOMDocument(); // since you have a fragment, wrap it in a <body> $dom->loadHTML("<body>".$str."</body>"); $links = $dom->getElementsByTagName("a"); while($link = $links[0]) { $link->parentNode->insertBefore(new DOMText($link->getAttribute("href")),$link); $link->parentNode->removeChild($link); } $result = $dom->saveHTML($dom->getElementsByTagName("body")[0]); // remove <body>..</body> wrapper $output = substr($result, strlen("<body>"), -strlen("</body>")); echo $output;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 14
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 14
Branch analysis from position: 32
Branch analysis from position: 14
filename:       /in/7Wgqn
function name:  (null)
number of ops:  49
compiled vars:  !0 = $str, !1 = $dom, !2 = $links, !3 = $link, !4 = $result, !5 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'This+is+a+text+with+multiple+anchor+tags.+This+is+the+first+one%3A+%3Ca+href%3D%22https%3A%2F%2Fwww.link1.com%2F%22+title%3D%22Link+1%22%3ELink+1%3C%2Fa%3E+and+this+one+the+second%3A+%3Ca+href%3D%22https%3A%2F%2Fwww.link2.com%2F%22+title%3D%22Link+2%22%3ELink+2%3C%2Fa%3E+after+that+a+lot+of+other+text.+And+here+the+3rd+one%3A+%3Ca+href%3D%22https%3A%2F%2Fwww.link3.com%2F%22+title%3D%22Link+3%22%3ELink+3%3C%2Fa%3E+Some+other+text.'
    5     1        NEW                                              $7      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $7
    7     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        CONCAT                                           ~10     '%3Cbody%3E', !0
          6        CONCAT                                           ~11     ~10, '%3C%2Fbody%3E'
          7        SEND_VAL_EX                                              ~11
          8        DO_FCALL                                      0          
    8     9        INIT_METHOD_CALL                                         !1, 'getElementsByTagName'
         10        SEND_VAL_EX                                              'a'
         11        DO_FCALL                                      0  $13     
         12        ASSIGN                                                   !2, $13
    9    13      > JMP                                                      ->29
   10    14    >   FETCH_OBJ_R                                      ~15     !3, 'parentNode'
         15        INIT_METHOD_CALL                                         ~15, 'insertBefore'
         16        NEW                                              $16     'DOMText'
         17        INIT_METHOD_CALL                                         !3, 'getAttribute'
         18        SEND_VAL_EX                                              'href'
         19        DO_FCALL                                      0  $17     
         20        SEND_VAR_NO_REF_EX                                       $17
         21        DO_FCALL                                      0          
         22        SEND_VAR_NO_REF_EX                                       $16
         23        SEND_VAR_EX                                              !3
         24        DO_FCALL                                      0          
   11    25        FETCH_OBJ_R                                      ~20     !3, 'parentNode'
         26        INIT_METHOD_CALL                                         ~20, 'removeChild'
         27        SEND_VAR_EX                                              !3
         28        DO_FCALL                                      0          
    9    29    >   FETCH_DIM_R                                      ~22     !2, 0
         30        ASSIGN                                           ~23     !3, ~22
         31      > JMPNZ                                                    ~23, ->14
   13    32    >   INIT_METHOD_CALL                                         !1, 'saveHTML'
         33        CHECK_FUNC_ARG                                           
         34        INIT_METHOD_CALL                                         !1, 'getElementsByTagName'
         35        SEND_VAL_EX                                              'body'
         36        DO_FCALL                                      0  $24     
         37        FETCH_DIM_FUNC_ARG                               $25     $24, 0
         38        SEND_FUNC_ARG                                            $25
         39        DO_FCALL                                      0  $26     
         40        ASSIGN                                                   !4, $26
   15    41        INIT_FCALL                                               'substr'
         42        SEND_VAR                                                 !4
         43        SEND_VAL                                                 6
         44        SEND_VAL                                                 -7
         45        DO_ICALL                                         $28     
         46        ASSIGN                                                   !5, $28
   17    47        ECHO                                                     !5
   18    48      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.61 ms | 1441 KiB | 14 Q