3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<'HTML' <body> <div id="entry"> <div class="one foo ">bla bla bla</div><!-- удалить --> <div class="world bar">bla bla bla</div> <div class="two bar">bla bla bla</div> <div class="three foo ">bla bla bla</div><!-- удалить --> <div class="paper bar">bla bla bla</div> <div class="boo bar loo">bla bla bla</div> </div> </body> HTML; $dom = new DOMDocument; @$dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $xpath = new DomXPath($dom); $entry = $xpath->query('//div[contains(@id, \'entry\')]/node()'); $content = ''; foreach($entry as $element) { if ( $xpath->evaluate('//self::div[contains(@class, \'foo\')]', $element) ) { continue; } else { $content .= $dom->saveHTML($element); } } echo $content; // После обработки должно быть так: // //<div class="world bar">bla bla bla</div> //<div class="two bar">bla bla bla</div> //<div class="paper bar">bla bla bla</div> //<div class="boo bar loo">bla bla bla</div>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 33
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 33
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 28
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/CfvAL
function name:  (null)
number of ops:  36
compiled vars:  !0 = $html, !1 = $dom, !2 = $xpath, !3 = $entry, !4 = $content, !5 = $element
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Cbody%3E%0A++%3Cdiv+id%3D%22entry%22%3E%0A%09%3Cdiv+class%3D%22one+foo+%22%3Ebla+bla+bla%3C%2Fdiv%3E%3C%21--+%D1%83%D0%B4%D0%B0%D0%BB%D0%B8%D1%82%D1%8C+--%3E%0A%09%3Cdiv+class%3D%22world+bar%22%3Ebla+bla+bla%3C%2Fdiv%3E%0A%09%3Cdiv+class%3D%22two+bar%22%3Ebla+bla+bla%3C%2Fdiv%3E%0A%09%3Cdiv+class%3D%22three+foo+%22%3Ebla+bla+bla%3C%2Fdiv%3E%3C%21--+%D1%83%D0%B4%D0%B0%D0%BB%D0%B8%D1%82%D1%8C+--%3E%0A%09%3Cdiv+class%3D%22paper+bar%22%3Ebla+bla+bla%3C%2Fdiv%3E%0A%09%3Cdiv+class%3D%22boo+bar+loo%22%3Ebla+bla+bla%3C%2Fdiv%3E%0A++%3C%2Fdiv%3E%0A%3C%2Fbody%3E'
   16     1        NEW                                              $7      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $7
   17     4        BEGIN_SILENCE                                    ~10     
          5        INIT_METHOD_CALL                                         !1, 'loadHTML'
          6        SEND_VAR_EX                                              !0
          7        SEND_VAL_EX                                              8196
          8        DO_FCALL                                      0          
          9        END_SILENCE                                              ~10
   18    10        NEW                                              $12     'DomXPath'
         11        SEND_VAR_EX                                              !1
         12        DO_FCALL                                      0          
         13        ASSIGN                                                   !2, $12
   19    14        INIT_METHOD_CALL                                         !2, 'query'
         15        SEND_VAL_EX                                              '%2F%2Fdiv%5Bcontains%28%40id%2C+%27entry%27%29%5D%2Fnode%28%29'
         16        DO_FCALL                                      0  $15     
         17        ASSIGN                                                   !3, $15
   21    18        ASSIGN                                                   !4, ''
   23    19      > FE_RESET_R                                       $18     !3, ->33
         20    > > FE_FETCH_R                                               $18, !5, ->33
   24    21    >   INIT_METHOD_CALL                                         !2, 'evaluate'
         22        SEND_VAL_EX                                              '%2F%2Fself%3A%3Adiv%5Bcontains%28%40class%2C+%27foo%27%29%5D'
         23        SEND_VAR_EX                                              !5
         24        DO_FCALL                                      0  $19     
         25      > JMPZ                                                     $19, ->28
   25    26    > > JMP                                                      ->20
         27*       JMP                                                      ->32
   28    28    >   INIT_METHOD_CALL                                         !1, 'saveHTML'
         29        SEND_VAR_EX                                              !5
         30        DO_FCALL                                      0  $20     
         31        ASSIGN_OP                                     8          !4, $20
   23    32      > JMP                                                      ->20
         33    >   FE_FREE                                                  $18
   32    34        ECHO                                                     !4
   39    35      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.31 ms | 1403 KiB | 13 Q