3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Load up the HTML in DOMDocument $doc = new DOMDocument; $doc->loadHTML( '<a class="modal">Stuff</a>'); // Or: $doc->loadHTML( $this->form->getInput('image_intro', 'images')); // Create a new XPath object to find the correct <a> tags $xpath = new DOMXPath( $doc); // Iterate over all <a class="modal"> tags foreach( $xpath->query( "//a[@class='modal']") as $a) { // Set the class attribute correctly $a->setAttribute( 'class', $a->getAttribute( 'class') . '-link'); echo $doc->saveHTML( $a); // Print the fixed <a> tag }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 28
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 28
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
filename:       /in/Zbdrd
function name:  (null)
number of ops:  30
compiled vars:  !0 = $doc, !1 = $xpath, !2 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   NEW                                              $3      'DOMDocument'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $3
    4     3        INIT_METHOD_CALL                                         !0, 'loadHTML'
          4        SEND_VAL_EX                                              '%3Ca+class%3D%22modal%22%3EStuff%3C%2Fa%3E'
          5        DO_FCALL                                      0          
    7     6        NEW                                              $7      'DOMXPath'
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !1, $7
   10    10        INIT_METHOD_CALL                                         !1, 'query'
         11        SEND_VAL_EX                                              '%2F%2Fa%5B%40class%3D%27modal%27%5D'
         12        DO_FCALL                                      0  $10     
         13      > FE_RESET_R                                       $11     $10, ->28
         14    > > FE_FETCH_R                                               $11, !2, ->28
   12    15    >   INIT_METHOD_CALL                                         !2, 'setAttribute'
         16        SEND_VAL_EX                                              'class'
         17        INIT_METHOD_CALL                                         !2, 'getAttribute'
         18        SEND_VAL_EX                                              'class'
         19        DO_FCALL                                      0  $12     
         20        CONCAT                                           ~13     $12, '-link'
         21        SEND_VAL_EX                                              ~13
         22        DO_FCALL                                      0          
   13    23        INIT_METHOD_CALL                                         !0, 'saveHTML'
         24        SEND_VAR_EX                                              !2
         25        DO_FCALL                                      0  $15     
         26        ECHO                                                     $15
   10    27      > JMP                                                      ->14
         28    >   FE_FREE                                                  $11
   14    29      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.88 ms | 1395 KiB | 13 Q