3v4l.org

run code in 500+ PHP versions simultaneously
<?php error_reporting(E_ALL); $htmlString = <<<_HTML <div> <a href="A"><img src="X"></a> <a href="C"><img src="X"></a> <a href="D"><img src="X"></a> <a href="E"><img src="X"></a> <a href="F"><img src="X"></a> <p> <a href="G"><img src="X"></a> </p> <a href="H">No image in this one</a> </div> _HTML; $doc = new DOMDocument(); $doc->loadHTML($htmlString, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $xpath = new DOMXPath($doc); $links = $xpath->query('//a[@href and img]'); foreach ($links as $link) { $link->setAttribute('href', 'B'); } $newHtmlString = $doc->saveHTML(); echo $newHtmlString;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 26
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 26
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/ZHTYG
function name:  (null)
number of ops:  32
compiled vars:  !0 = $htmlString, !1 = $doc, !2 = $xpath, !3 = $links, !4 = $link, !5 = $newHtmlString
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                                   'error_reporting'
          1        SEND_VAL                                                     30719
          2        DO_ICALL                                                     
    4     3        ASSIGN                                                       !0, '%3Cdiv%3E%0A%3Ca+href%3D%22A%22%3E%3Cimg+src%3D%22X%22%3E%3C%2Fa%3E%0A%3Ca+href%3D%22C%22%3E%3Cimg+src%3D%22X%22%3E%3C%2Fa%3E%0A%3Ca+href%3D%22D%22%3E%3Cimg+src%3D%22X%22%3E%3C%2Fa%3E%0A%3Ca+href%3D%22E%22%3E%3Cimg+src%3D%22X%22%3E%3C%2Fa%3E%0A%3Ca+href%3D%22F%22%3E%3Cimg+src%3D%22X%22%3E%3C%2Fa%3E%0A%3Cp%3E%0A++%3Ca+href%3D%22G%22%3E%3Cimg+src%3D%22X%22%3E%3C%2Fa%3E%0A%3C%2Fp%3E%0A%3Ca+href%3D%22H%22%3ENo+image+in+this+one%3C%2Fa%3E%0A%3C%2Fdiv%3E'
   18     4        NEW                                                  $8      'DOMDocument'
          5        DO_FCALL                                          0          
          6        ASSIGN                                                       !1, $8
   19     7        INIT_METHOD_CALL                                             !1, 'loadHTML'
          8        SEND_VAR_EX                                                  !0
          9        SEND_VAL_EX                                                  8196
         10        DO_FCALL                                          0          
   21    11        NEW                                                  $12     'DOMXPath'
         12        SEND_VAR_EX                                                  !1
         13        DO_FCALL                                          0          
         14        ASSIGN                                                       !2, $12
   22    15        INIT_METHOD_CALL                                             !2, 'query'
         16        SEND_VAL_EX                                                  '%2F%2Fa%5B%40href+and+img%5D'
         17        DO_FCALL                                          0  $15     
         18        ASSIGN                                                       !3, $15
   23    19      > FE_RESET_R                                           $17     !3, ->26
         20    > > FE_FETCH_R                                                   $17, !4, ->26
   24    21    >   INIT_METHOD_CALL                                             !4, 'setAttribute'
         22        SEND_VAL_EX                                                  'href'
         23        SEND_VAL_EX                                                  'B'
         24        DO_FCALL                                          0          
   23    25      > JMP                                                          ->20
         26    >   FE_FREE                                                      $17
   26    27        INIT_METHOD_CALL                                             !1, 'saveHTML'
         28        DO_FCALL                                          0  $19     
         29        ASSIGN                                                       !5, $19
   28    30        ECHO                                                         !5
         31      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
226.61 ms | 2292 KiB | 14 Q