3v4l.org

run code in 500+ PHP versions simultaneously
<?php $html = <<<'HTML' <div class="blockImg imgRight"> <img src="customs/2/pictures/home.png"> <figcaption>Une légende</figcaption> </div> HTML; // on ajoute la structure manquante pour préciser l'encodage $html = <<<HTML <html><head><meta charset="utf-8"/></head><body>$html</body></html> HTML; $dom = new \DOMDocument; $dom->loadHTML($html, LIBXML_NOERROR); $context = $dom->getElementsByTagName('div')[0]; $xp = new \DOMXPath($dom); // on extrait la valeur de l'attribut class tout en vérifiant la présence de la classe "blockImg" $classAttrValue = $xp->evaluate( 'string(@class[contains(concat(" ", normalize-space(.), " "), " blockImg ")])', $context ); if ($classAttrValue && preg_match('~ \b img (?: Right | Left ) \b ~x', $classAttrValue, $m)) { $class = $m[0]; $src = $xp->evaluate('string(img/@src)', $context); $filename = basename($src); $caption = $xp->evaluate('string(figcaption)', $context); echo $class, PHP_EOL, $src, PHP_EOL, $filename, PHP_EOL, $caption, PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 27, Position 2 = 33
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 58
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 58
Branch analysis from position: 33
filename:       /in/QCoeM
function name:  (null)
number of ops:  59
compiled vars:  !0 = $html, !1 = $dom, !2 = $context, !3 = $xp, !4 = $classAttrValue, !5 = $m, !6 = $class, !7 = $src, !8 = $filename, !9 = $caption
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '%3Cdiv+class%3D%22blockImg+imgRight%22%3E%0A%09%3Cimg+src%3D%22customs%2F2%2Fpictures%2Fhome.png%22%3E%0A%09%3Cfigcaption%3EUne+l%C3%A9gende%3C%2Ffigcaption%3E%0A%3C%2Fdiv%3E'
   12     1        ROPE_INIT                                         3  ~12     '%3Chtml%3E%3Chead%3E%3Cmeta+charset%3D%22utf-8%22%2F%3E%3C%2Fhead%3E%3Cbody%3E'
          2        ROPE_ADD                                          1  ~12     ~12, !0
          3        ROPE_END                                          2  ~11     ~12, '%3C%2Fbody%3E%3C%2Fhtml%3E'
   11     4        ASSIGN                                                       !0, ~11
   15     5        NEW                                                  $15     'DOMDocument'
          6        DO_FCALL                                          0          
          7        ASSIGN                                                       !1, $15
   16     8        INIT_METHOD_CALL                                             !1, 'loadHTML'
          9        SEND_VAR_EX                                                  !0
         10        SEND_VAL_EX                                                  32
         11        DO_FCALL                                          0          
   18    12        INIT_METHOD_CALL                                             !1, 'getElementsByTagName'
         13        SEND_VAL_EX                                                  'div'
         14        DO_FCALL                                          0  $19     
         15        FETCH_DIM_R                                          ~20     $19, 0
         16        ASSIGN                                                       !2, ~20
   20    17        NEW                                                  $22     'DOMXPath'
         18        SEND_VAR_EX                                                  !1
         19        DO_FCALL                                          0          
         20        ASSIGN                                                       !3, $22
   23    21        INIT_METHOD_CALL                                             !3, 'evaluate'
   24    22        SEND_VAL_EX                                                  'string%28%40class%5Bcontains%28concat%28%22+%22%2C+normalize-space%28.%29%2C+%22+%22%29%2C+%22+blockImg+%22%29%5D%29'
         23        SEND_VAR_EX                                                  !2
   23    24        DO_FCALL                                          0  $25     
         25        ASSIGN                                                       !4, $25
   28    26      > JMPZ_EX                                              ~27     !4, ->33
         27    >   INIT_FCALL                                                   'preg_match'
         28        SEND_VAL                                                     '%7E+%5Cb+img+%28%3F%3A+Right+%7C+Left+%29+%5Cb+%7Ex'
         29        SEND_VAR                                                     !4
         30        SEND_REF                                                     !5
         31        DO_ICALL                                             $28     
         32        BOOL                                                 ~27     $28
         33    > > JMPZ                                                         ~27, ->58
   29    34    >   FETCH_DIM_R                                          ~29     !5, 0
         35        ASSIGN                                                       !6, ~29
   30    36        INIT_METHOD_CALL                                             !3, 'evaluate'
         37        SEND_VAL_EX                                                  'string%28img%2F%40src%29'
         38        SEND_VAR_EX                                                  !2
         39        DO_FCALL                                          0  $31     
         40        ASSIGN                                                       !7, $31
   31    41        INIT_FCALL                                                   'basename'
         42        SEND_VAR                                                     !7
         43        DO_ICALL                                             $33     
         44        ASSIGN                                                       !8, $33
   32    45        INIT_METHOD_CALL                                             !3, 'evaluate'
         46        SEND_VAL_EX                                                  'string%28figcaption%29'
         47        SEND_VAR_EX                                                  !2
         48        DO_FCALL                                          0  $35     
         49        ASSIGN                                                       !9, $35
   34    50        ECHO                                                         !6
         51        ECHO                                                         '%0A'
         52        ECHO                                                         !7
         53        ECHO                                                         '%0A'
         54        ECHO                                                         !8
         55        ECHO                                                         '%0A'
         56        ECHO                                                         !9
         57        ECHO                                                         '%0A'
   35    58    > > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
126.74 ms | 485 KiB | 9 Q