3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = '<a href="#"><img src="image1"></a>blabla<a href="#">Without an image</a><a href="#"><img src="image2"></a>'; $domDocument = new \DOMDocument(); $domDocument->loadHTML($html); $xpath = new DOMXPath($domDocument); foreach ($xpath->query('//a[./img]') as $imageLink) { echo $domDocument->saveHTML($imageLink), PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 22
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 22
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/GXAbC
function name:  (null)
number of ops:  24
compiled vars:  !0 = $html, !1 = $domDocument, !2 = $xpath, !3 = $imageLink
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Ca+href%3D%22%23%22%3E%3Cimg+src%3D%22image1%22%3E%3C%2Fa%3Eblabla%3Ca+href%3D%22%23%22%3EWithout+an+image%3C%2Fa%3E%3Ca+href%3D%22%23%22%3E%3Cimg+src%3D%22image2%22%3E%3C%2Fa%3E'
    5     1        NEW                                              $5      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $5
    6     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
    8     7        NEW                                              $9      'DOMXPath'
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !2, $9
    9    11        INIT_METHOD_CALL                                         !2, 'query'
         12        SEND_VAL_EX                                              '%2F%2Fa%5B.%2Fimg%5D'
         13        DO_FCALL                                      0  $12     
         14      > FE_RESET_R                                       $13     $12, ->22
         15    > > FE_FETCH_R                                               $13, !3, ->22
   10    16    >   INIT_METHOD_CALL                                         !1, 'saveHTML'
         17        SEND_VAR_EX                                              !3
         18        DO_FCALL                                      0  $14     
         19        ECHO                                                     $14
         20        ECHO                                                     '%0A'
    9    21      > JMP                                                      ->15
         22    >   FE_FREE                                                  $13
   11    23      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.45 ms | 995 KiB | 13 Q