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 = ' <a href="http://inorbit.in/whitefield/wp-content/uploads/sites/4/2014/06/Interschool-championship.gif"><a href="http://inorbit.in/whitefield/wp-content/uploads/sites/4/2014/06/IMG_0889.jpg"><img class="aligncenter size-full wp-image-1928" alt="sports championship competition" src="http://inorbit.in/whitefield/wp-content/uploads/sites/4/2014/06/IMG_0889.jpg" width="1024" height="768" /></a><a href="http://inorbit.in/whitefield/wp-content/uploads/sites/4/2014/06/IMG_0830.jpg"><img class="aligncenter size-full wp-image-1929" alt="sports championship competition" src="http://inorbit.in/whitefield/wp-content/uploads/sites/4/2014/06/IMG_0830.jpg" width="1024" height="768" /></a></a>'; // ok test( $input);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RuNQD
function name:  (null)
number of ops:  5
compiled vars:  !0 = $input
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   ASSIGN                                                   !0, '%0A%3Ca+href%3D%22http%3A%2F%2Finorbit.in%2Fwhitefield%2Fwp-content%2Fuploads%2Fsites%2F4%2F2014%2F06%2FInterschool-championship.gif%22%3E%3Ca+href%3D%22http%3A%2F%2Finorbit.in%2Fwhitefield%2Fwp-content%2Fuploads%2Fsites%2F4%2F2014%2F06%2FIMG_0889.jpg%22%3E%3Cimg+class%3D%22aligncenter+size-full+wp-image-1928%22+alt%3D%22sports+championship+competition%22+src%3D%22http%3A%2F%2Finorbit.in%2Fwhitefield%2Fwp-content%2Fuploads%2Fsites%2F4%2F2014%2F06%2FIMG_0889.jpg%22+width%3D%221024%22+height%3D%22768%22+%2F%3E%3C%2Fa%3E%3Ca+href%3D%22http%3A%2F%2Finorbit.in%2Fwhitefield%2Fwp-content%2Fuploads%2Fsites%2F4%2F2014%2F06%2FIMG_0830.jpg%22%3E%3Cimg+class%3D%22aligncenter+size-full+wp-image-1929%22+alt%3D%22sports+championship+competition%22+src%3D%22http%3A%2F%2Finorbit.in%2Fwhitefield%2Fwp-content%2Fuploads%2Fsites%2F4%2F2014%2F06%2FIMG_0830.jpg%22+width%3D%221024%22+height%3D%22768%22+%2F%3E%3C%2Fa%3E%3C%2Fa%3E'
   34     1        INIT_FCALL                                               'test'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0          
          4      > 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/RuNQD
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:
157.47 ms | 1402 KiB | 14 Q