3v4l.org

run code in 300+ PHP versions simultaneously
<?php $dom = new DOMDocument(); $dom->loadHtml(' <a href="http://example.com/books/1">The Lord of the Rings</a> <ul> <li><a href="http://example.com/books/1#c1" >Chapter 1</a></li> <li><a name="name before href" href="http://example.com/books/1#c2">Chapter 2</a></li> <li><a href="http://example.com/books/1#c3" name="name after href">Chapter 3</a></li> <li><a href="http://example.com/books/1#cN" target="_blank">Chapter N</a></li> </ul> <br><br> <a href="http://example.com/books/1">Harry Potter</a> <ul> <li><a href="http://example.com/books/2#c1" target="_self">Chapter 1</a></li> <li><a href="http://example.com/books/2#c2" name="some have name" title="some others have title" >Chapter 2</a></li> <li><a href="http://example.com/books/2#c3">Chapter 3</a></li> <li><a href="http://example.com/books/2#cN" >Chapter N</a></li> </ul> ', LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $xpath = new DOMXPath($dom); foreach ($xpath->query("//a") as $link) { $href = $link->getAttribute('href'); if (strpos($href, '#') !== false) { $link->parentNode->nodeValue = $link->nodeValue; } } echo $dom->saveHTML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 31
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 31
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 30
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 30
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/8FQYb
function name:  (null)
number of ops:  36
compiled vars:  !0 = $dom, !1 = $xpath, !2 = $link, !3 = $href
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   NEW                                              $4      'DOMDocument'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $4
    4     3        INIT_METHOD_CALL                                         !0, 'loadHtml'
          4        SEND_VAL_EX                                              '%0A%3Ca+href%3D%22http%3A%2F%2Fexample.com%2Fbooks%2F1%22%3EThe+Lord+of+the+Rings%3C%2Fa%3E%0A%3Cul%3E%0A++++%3Cli%3E%3Ca+++href%3D%22http%3A%2F%2Fexample.com%2Fbooks%2F1%23c1%22+%3EChapter+1%3C%2Fa%3E%3C%2Fli%3E%0A++++%3Cli%3E%3Ca+name%3D%22name+before+href%22+href%3D%22http%3A%2F%2Fexample.com%2Fbooks%2F1%23c2%22%3EChapter+2%3C%2Fa%3E%3C%2Fli%3E%0A++++%3Cli%3E%3Ca+href%3D%22http%3A%2F%2Fexample.com%2Fbooks%2F1%23c3%22+name%3D%22name+after+href%22%3EChapter+3%3C%2Fa%3E%3C%2Fli%3E%0A++++%3Cli%3E%3Ca+href%3D%22http%3A%2F%2Fexample.com%2Fbooks%2F1%23cN%22+target%3D%22_blank%22%3EChapter+N%3C%2Fa%3E%3C%2Fli%3E%0A%3C%2Ful%3E%0A%3Cbr%3E%3Cbr%3E%0A%3Ca+href%3D%22http%3A%2F%2Fexample.com%2Fbooks%2F1%22%3EHarry+Potter%3C%2Fa%3E%0A%3Cul%3E%0A++++%3Cli%3E%3Ca+href%3D%22http%3A%2F%2Fexample.com%2Fbooks%2F2%23c1%22+target%3D%22_self%22%3EChapter+1%3C%2Fa%3E%3C%2Fli%3E%0A++++%3Cli%3E%3Ca+href%3D%22http%3A%2F%2Fexample.com%2Fbooks%2F2%23c2%22+name%3D%22some+have+name%22+title%3D%22some+others+have+title%22+%3EChapter+2%3C%2Fa%3E%3C%2Fli%3E%0A++++%3Cli%3E%3Ca+href%3D%22http%3A%2F%2Fexample.com%2Fbooks%2F2%23c3%22%3EChapter+3%3C%2Fa%3E%3C%2Fli%3E%0A++++%3Cli%3E%3Ca+href%3D%22http%3A%2F%2Fexample.com%2Fbooks%2F2%23cN%22++%3EChapter+N%3C%2Fa%3E%3C%2Fli%3E%0A%3C%2Ful%3E%0A'
   20     5        SEND_VAL_EX                                              8196
    4     6        DO_FCALL                                      0          
   22     7        NEW                                              $8      'DOMXPath'
          8        SEND_VAR_EX                                              !0
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !1, $8
   24    11        INIT_METHOD_CALL                                         !1, 'query'
         12        SEND_VAL_EX                                              '%2F%2Fa'
         13        DO_FCALL                                      0  $11     
         14      > FE_RESET_R                                       $12     $11, ->31
         15    > > FE_FETCH_R                                               $12, !2, ->31
   25    16    >   INIT_METHOD_CALL                                         !2, 'getAttribute'
         17        SEND_VAL_EX                                              'href'
         18        DO_FCALL                                      0  $13     
         19        ASSIGN                                                   !3, $13
   27    20        INIT_FCALL                                               'strpos'
         21        SEND_VAR                                                 !3
         22        SEND_VAL                                                 '%23'
         23        DO_ICALL                                         $15     
         24        TYPE_CHECK                                  1018          $15
         25      > JMPZ                                                     ~16, ->30
   28    26    >   FETCH_OBJ_R                                      ~19     !2, 'nodeValue'
         27        FETCH_OBJ_W                                      $17     !2, 'parentNode'
         28        ASSIGN_OBJ                                               $17, 'nodeValue'
         29        OP_DATA                                                  ~19
   24    30    > > JMP                                                      ->15
         31    >   FE_FREE                                                  $12
   32    32        INIT_METHOD_CALL                                         !0, 'saveHTML'
         33        DO_FCALL                                      0  $20     
         34        ECHO                                                     $20
         35      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.33 ms | 1450 KiB | 14 Q