3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<'HTML' <body> <div id="entry1"> <div class="one foo ">1bla 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\')]/div'); $content = ''; foreach($entry as $element) { if(! $xpath->evaluate("contains(@class, 'foo')", $element)) { $content .= $dom->saveHTML($element) . PHP_EOL; } } echo $content;
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 = 27, Position 2 = 32
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 32
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/FhNUp
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%09%3Cdiv+id%3D%22entry1%22%3E%0A%09%09%3Cdiv+class%3D%22one+foo+%22%3E1bla+bla+bla%3C%2Fdiv%3E%3C%21--+%D1%83%D0%B4%D0%B0%D0%BB%D0%B8%D1%82%D1%8C+--%3E%0A%09%09%3Cdiv+class%3D%22world+bar%22%3Ebla+bla+bla%3C%2Fdiv%3E%0A%09%09%3Cdiv+class%3D%22two+bar%22%3Ebla+bla+bla%3C%2Fdiv%3E%0A%09%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%09%3Cdiv+class%3D%22paper+bar%22%3Ebla+bla+bla%3C%2Fdiv%3E%0A%09%09%3Cdiv+class%3D%22boo+bar+loo%22%3Ebla+bla+bla%3C%2Fdiv%3E%0A%09%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%2Fdiv'
         16        DO_FCALL                                      0  $15     
         17        ASSIGN                                                   !3, $15
   21    18        ASSIGN                                                   !4, ''
   22    19      > FE_RESET_R                                       $18     !3, ->33
         20    > > FE_FETCH_R                                               $18, !5, ->33
   23    21    >   INIT_METHOD_CALL                                         !2, 'evaluate'
         22        SEND_VAL_EX                                              'contains%28%40class%2C+%27foo%27%29'
         23        SEND_VAR_EX                                              !5
         24        DO_FCALL                                      0  $19     
         25        BOOL_NOT                                         ~20     $19
         26      > JMPZ                                                     ~20, ->32
   24    27    >   INIT_METHOD_CALL                                         !1, 'saveHTML'
         28        SEND_VAR_EX                                              !5
         29        DO_FCALL                                      0  $21     
         30        CONCAT                                           ~22     $21, '%0A'
         31        ASSIGN_OP                                     8          !4, ~22
   22    32    > > JMP                                                      ->20
         33    >   FE_FREE                                                  $18
   28    34        ECHO                                                     !4
   29    35      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.62 ms | 1403 KiB | 13 Q