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; $error = false; foreach( $children as $child) { 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"; $error = true; } else { $img_found = true; } } else { // echo "Invalid node type!"; $error = true; } } if( $img_found && !$error) { echo 'ok' . "\n"; } else { echo 'NOT ok' . "\n"; } } $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/s468l
function name:  (null)
number of ops:  17
compiled vars:  !0 = $input
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   ASSIGN                                                   !0, '%3Cp%3E%3Cimg+src%3D%22%23%22+%2F%3E%3C%2Fp%3E'
   33     1        INIT_FCALL                                               'test'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0          
   35     4        ASSIGN                                                   !0, '%3Cp%3E%3Cimg+src%3D%22%23%22+%2F%3E%3Cimg+src%3D%22%23%22+%2F%3E%3C%2Fp%3E'
   36     5        INIT_FCALL                                               'test'
          6        SEND_VAR                                                 !0
          7        DO_FCALL                                      0          
   38     8        ASSIGN                                                   !0, '%3Cp%3Exxx%3Cimg+src%3D%22%23%22+%2F%3E%3C%2Fp%3E'
   39     9        INIT_FCALL                                               'test'
         10        SEND_VAR                                                 !0
         11        DO_FCALL                                      0          
   41    12        ASSIGN                                                   !0, '%3Cp%3E%3Cimg+src%3D%22%23%22+%2F%3Exxx%3C%2Fp%3E'
   42    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 = 19, Position 2 = 40
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 40
Branch analysis from position: 20
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 = 19
Branch analysis from position: 19
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 = 19
Branch analysis from position: 19
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 = 19
Branch analysis from position: 19
Branch analysis from position: 25
Branch analysis from position: 40
2 jumps found. (Code = 46) Position 1 = 42, Position 2 = 44
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 47
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
Branch analysis from position: 40
filename:       /in/s468l
function name:  test
number of ops:  49
compiled vars:  !0 = $input, !1 = $doc, !2 = $p, !3 = $children, !4 = $img_found, !5 = $error, !6 = $child
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        NEW                                              $7      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $7
    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  $11     
         10        INIT_METHOD_CALL                                         $11, 'item'
         11        SEND_VAL_EX                                              0
         12        DO_FCALL                                      0  $12     
         13        ASSIGN                                                   !2, $12
    6    14        FETCH_OBJ_R                                      ~14     !2, 'childNodes'
         15        ASSIGN                                                   !3, ~14
    7    16        ASSIGN                                                   !4, <false>
         17        ASSIGN                                                   !5, <false>
    8    18      > FE_RESET_R                                       $18     !3, ->40
         19    > > FE_FETCH_R                                               $18, !6, ->40
    9    20    >   FETCH_OBJ_R                                      ~19     !6, 'nodeType'
         21        IS_EQUAL                                         ~20     ~19, 3
         22      > JMPZ_EX                                          ~20     ~20, ->25
         23    >   BOOL_NOT                                         ~21     !4
         24        BOOL                                             ~20     ~21
         25    > > JMPZ                                                     ~20, ->27
   11    26    > > JMP                                                      ->19
   13    27    >   FETCH_OBJ_R                                      ~22     !6, 'nodeType'
         28        IS_EQUAL                                                 ~22, 1
         29      > JMPZ                                                     ~23, ->38
   14    30    >   FETCH_OBJ_R                                      ~24     !6, 'tagName'
         31        IS_EQUAL                                         ~25     ~24, 'img'
         32        BOOL_NOT                                         ~26     ~25
         33      > JMPZ                                                     ~26, ->36
   16    34    >   ASSIGN                                                   !5, <true>
         35      > JMP                                                      ->37
   18    36    >   ASSIGN                                                   !4, <true>
         37    > > JMP                                                      ->39
   22    38    >   ASSIGN                                                   !5, <true>
    8    39    > > JMP                                                      ->19
         40    >   FE_FREE                                                  $18
   25    41      > JMPZ_EX                                          ~30     !4, ->44
         42    >   BOOL_NOT                                         ~31     !5
         43        BOOL                                             ~30     ~31
         44    > > JMPZ                                                     ~30, ->47
   26    45    >   ECHO                                                     'ok%0A'
         46      > JMP                                                      ->48
   28    47    >   ECHO                                                     'NOT+ok%0A'
   30    48    > > RETURN                                                   null

End of function test

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.88 ms | 1403 KiB | 17 Q