3v4l.org

run code in 500+ 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 = 28
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 28
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 27
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 27
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
filename:       /in/8FQYb
function name:  (null)
number of ops:  33
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, ->28
         15    > > FE_FETCH_R                                                   $12, !2, ->28
   25    16    >   INIT_METHOD_CALL                                             !2, 'getAttribute'
         17        SEND_VAL_EX                                                  'href'
         18        DO_FCALL                                          0  $13     
         19        ASSIGN                                                       !3, $13
   27    20        FRAMELESS_ICALL_2                strpos              ~15     !3, '%23'
         21        TYPE_CHECK                                      1018          ~15
         22      > JMPZ                                                         ~16, ->27
   28    23    >   FETCH_OBJ_R                                          ~19     !2, 'nodeValue'
         24        FETCH_OBJ_W                                          $17     !2, 'parentNode'
         25        ASSIGN_OBJ                                                   $17, 'nodeValue'
         26        OP_DATA                                                      ~19
   24    27    > > JMP                                                          ->15
         28    >   FE_FREE                                                      $12
   32    29        INIT_METHOD_CALL                                             !0, 'saveHTML'
         30        DO_FCALL                                          0  $20     
         31        ECHO                                                         $20
         32      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
167.91 ms | 2655 KiB | 13 Q