3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <p>Ple ple ple BLA xo xo xo <span class="tooltip-content"><span class="tooltip-text">uuu BLA pla</span></span> he BLAZE he BLA he ha ha ha.</p> HTML; $find = 'BLA'; $doc = new DOMDocument(); $doc->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $xpath = new DOMXPath($doc); foreach ($xpath->query('//text()[not(ancestor::span[contains(@class, "tooltip-content")])]') as $node) { $node->nodeValue = preg_replace("/(\s)?\b$find\b(?(1)|\s*)/", '', $node->nodeValue); } echo $doc->saveHTML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 30
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 30
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/DYrrp
function name:  (null)
number of ops:  35
compiled vars:  !0 = $html, !1 = $find, !2 = $doc, !3 = $xpath, !4 = $node
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Cp%3EPle+ple+ple+BLA+xo+xo+xo+%3Cspan+class%3D%22tooltip-content%22%3E%3Cspan+class%3D%22tooltip-text%22%3Euuu+BLA+pla%3C%2Fspan%3E%3C%2Fspan%3E+he+BLAZE+he+BLA+he+ha+ha+ha.%3C%2Fp%3E'
    6     1        ASSIGN                                                   !1, 'BLA'
    8     2        NEW                                              $7      'DOMDocument'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !2, $7
    9     5        INIT_METHOD_CALL                                         !2, 'loadHTML'
          6        SEND_VAR_EX                                              !0
          7        SEND_VAL_EX                                              8196
          8        DO_FCALL                                      0          
   10     9        NEW                                              $11     'DOMXPath'
         10        SEND_VAR_EX                                              !2
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !3, $11
   11    13        INIT_METHOD_CALL                                         !3, 'query'
         14        SEND_VAL_EX                                              '%2F%2Ftext%28%29%5Bnot%28ancestor%3A%3Aspan%5Bcontains%28%40class%2C+%22tooltip-content%22%29%5D%29%5D'
         15        DO_FCALL                                      0  $14     
         16      > FE_RESET_R                                       $15     $14, ->30
         17    > > FE_FETCH_R                                               $15, !4, ->30
   12    18    >   INIT_FCALL                                               'preg_replace'
         19        ROPE_INIT                                     3  ~18     '%2F%28%5Cs%29%3F%5Cb'
         20        ROPE_ADD                                      1  ~18     ~18, !1
         21        ROPE_END                                      2  ~17     ~18, '%5Cb%28%3F%281%29%7C%5Cs%2A%29%2F'
         22        SEND_VAL                                                 ~17
         23        SEND_VAL                                                 ''
         24        FETCH_OBJ_R                                      ~20     !4, 'nodeValue'
         25        SEND_VAL                                                 ~20
         26        DO_ICALL                                         $21     
         27        ASSIGN_OBJ                                               !4, 'nodeValue'
         28        OP_DATA                                                  $21
   11    29      > JMP                                                      ->17
         30    >   FE_FREE                                                  $15
   14    31        INIT_METHOD_CALL                                         !2, 'saveHTML'
         32        DO_FCALL                                      0  $22     
         33        ECHO                                                     $22
         34      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.89 ms | 1011 KiB | 14 Q