3v4l.org

run code in 300+ PHP versions simultaneously
<?php function test( $input) { $doc = new DOMDocument; $doc->loadHTML( $input); $p = $doc->getElementsByTagName('p')->item(0); $children = $p->childNodes; $img_found = false; foreach( $children as $child) { echo 'In here'; if( $child->nodeType == XML_TEXT_NODE && !$img_found) { // Text before the image, OK, continue on continue; } if( $child->nodeType == XML_ELEMENT_NODE) { if( !($child->tagName == 'img')) { echo "Invalid HTML element found"; } else { $img_found = true; } } else { echo "Invalid node type!"; } } } $input = '<p><img src="#" /></p>'; // ok test( $input); $input = '<p><img src="#" /><img src="#" /></p>'; // ok test( $input); $input = '<p>xxx<img src="#" /></p>'; // ok test( $input); $input = '<p><img src="#" />xxx</p>'; // NOT ok test( $input);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XH8lN
function name:  (null)
number of ops:  17
compiled vars:  !0 = $input
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   ASSIGN                                                   !0, '%3Cp%3E%3Cimg+src%3D%22%23%22+%2F%3E%3C%2Fp%3E'
   27     1        INIT_FCALL                                               'test'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0          
   29     4        ASSIGN                                                   !0, '%3Cp%3E%3Cimg+src%3D%22%23%22+%2F%3E%3Cimg+src%3D%22%23%22+%2F%3E%3C%2Fp%3E'
   30     5        INIT_FCALL                                               'test'
          6        SEND_VAR                                                 !0
          7        DO_FCALL                                      0          
   32     8        ASSIGN                                                   !0, '%3Cp%3Exxx%3Cimg+src%3D%22%23%22+%2F%3E%3C%2Fp%3E'
   33     9        INIT_FCALL                                               'test'
         10        SEND_VAR                                                 !0
         11        DO_FCALL                                      0          
   35    12        ASSIGN                                                   !0, '%3Cp%3E%3Cimg+src%3D%22%23%22+%2F%3Exxx%3C%2Fp%3E'
   36    13        INIT_FCALL                                               'test'
         14        SEND_VAR                                                 !0
         15        DO_FCALL                                      0          
         16      > RETURN                                                   1

Function test:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 40
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 40
Branch analysis from position: 19
2 jumps found. (Code = 46) Position 1 = 23, Position 2 = 25
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 27
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 38
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 36
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 25
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
filename:       /in/XH8lN
function name:  test
number of ops:  42
compiled vars:  !0 = $input, !1 = $doc, !2 = $p, !3 = $children, !4 = $img_found, !5 = $child
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        NEW                                              $6      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $6
    4     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
    5     7        INIT_METHOD_CALL                                         !1, 'getElementsByTagName'
          8        SEND_VAL_EX                                              'p'
          9        DO_FCALL                                      0  $10     
         10        INIT_METHOD_CALL                                         $10, 'item'
         11        SEND_VAL_EX                                              0
         12        DO_FCALL                                      0  $11     
         13        ASSIGN                                                   !2, $11
    6    14        FETCH_OBJ_R                                      ~13     !2, 'childNodes'
         15        ASSIGN                                                   !3, ~13
    7    16        ASSIGN                                                   !4, <false>
    8    17      > FE_RESET_R                                       $16     !3, ->40
         18    > > FE_FETCH_R                                               $16, !5, ->40
    9    19    >   ECHO                                                     'In+here'
   10    20        FETCH_OBJ_R                                      ~17     !5, 'nodeType'
         21        IS_EQUAL                                         ~18     ~17, 3
         22      > JMPZ_EX                                          ~18     ~18, ->25
         23    >   BOOL_NOT                                         ~19     !4
         24        BOOL                                             ~18     ~19
         25    > > JMPZ                                                     ~18, ->27
   12    26    > > JMP                                                      ->18
   14    27    >   FETCH_OBJ_R                                      ~20     !5, 'nodeType'
         28        IS_EQUAL                                                 ~20, 1
         29      > JMPZ                                                     ~21, ->38
   15    30    >   FETCH_OBJ_R                                      ~22     !5, 'tagName'
         31        IS_EQUAL                                         ~23     ~22, 'img'
         32        BOOL_NOT                                         ~24     ~23
         33      > JMPZ                                                     ~24, ->36
   16    34    >   ECHO                                                     'Invalid+HTML+element+found'
         35      > JMP                                                      ->37
   18    36    >   ASSIGN                                                   !4, <true>
         37    > > JMP                                                      ->39
   21    38    >   ECHO                                                     'Invalid+node+type%21'
    8    39    > > JMP                                                      ->18
         40    >   FE_FREE                                                  $16
   24    41      > RETURN                                                   null

End of function test

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.07 ms | 1403 KiB | 17 Q