3v4l.org

run code in 500+ PHP versions simultaneously
<?php $html = ' <!DOCTYPE html> <html lang="fr"> <head> <meta charset="UTF-8"> <title>tester fusion</title> <style> span {color:red} .refid-valeur {white-space:nowrap} .char-style-override-6 {color:navy} </style> </head> <body> <div> <span class="refid-valeur char-style-override-6">special</span><span class="refid-valeur char-style-override-6"> </span><span class="refid-valeur char-style-override-6">espace</span> </div> <span class="refid-valeur char-style-override-6">RCR-ART-RCR-L</span><span class="refid-valeur char-style-override-6">213</span><span class="refid-valeur char-style-override-6">-1</span> <div> <span class="refid-valeur char-style-override-6">séquence avec child</span><span class="refid-valeur char-style-override-6"> P<span>A</span>S</span><span class="refid-valeur char-style-override-6"> </span><span class="refid-valeur char-style-override-6"><em>D</em>E PRO</span><span class="refid-valeur char-style-override-6">BLÈME</span><span class="refid-valeur char-style-override-6"> <strong>ICI</strong>?</span> </div> </body> </html> '; $dom = new DOMDocument; $dom->loadHTML($html, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED); $xp = new DOMXPath($dom); $firstElts = $xp->query('//span' // un element span n'importe où dans l'arbre DOM . '[@class="refid-valeur char-style-override-6"]' // avec l'attribut class recherché // qui n'est pas immédiatement précédé par un élément avec les mêmes caractéristiques . '[not(preceding-sibling::node()[1][local-name()="span"][@class="refid-valeur char-style-override-6"])]' // mais dont le nœud qui le suit immédiatement est un élément avec les mêmes caractéristiques . '[following-sibling::node()[1][local-name()="span"][@class="refid-valeur char-style-override-6"]]'); function isSameElt($node1, $node2) { if ( $node1->nodeName !== $node2->nodeName ) return false; if ( $node1->attributes->length !== $node2->attributes->length ) return false; foreach ( $node1->attributes as $attr ) { if ( !$node2->hasAttribute($attr->name) || $node2->getAttribute($attr->name) !== $attr->value ) return false; } return true; } $toDelete = []; foreach ($firstElts as $firstElt) { $current = $firstElt; while ( null !== $current = $current->nextSibling ) { if ( !isSameElt($firstElt, $current) ) break; foreach ($current->childNodes as $childNode) { $firstElt->appendChild($childNode); } $toDelete[] = $current; } } foreach ($toDelete as $node) { $node->parentNode->removeChild($node); } echo $dom->saveHTML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 43
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 43
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 21
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 28
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
Branch analysis from position: 28
2 jumps found. (Code = 77) Position 1 = 30, Position 2 = 35
Branch analysis from position: 30
2 jumps found. (Code = 78) Position 1 = 31, Position 2 = 35
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 21
Branch analysis from position: 42
Branch analysis from position: 21
Branch analysis from position: 35
Branch analysis from position: 43
2 jumps found. (Code = 77) Position 1 = 45, Position 2 = 51
Branch analysis from position: 45
2 jumps found. (Code = 78) Position 1 = 46, Position 2 = 51
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
Branch analysis from position: 51
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
Branch analysis from position: 43
filename:       /in/O1UNq
function name:  (null)
number of ops:  56
compiled vars:  !0 = $html, !1 = $dom, !2 = $xp, !3 = $firstElts, !4 = $toDelete, !5 = $firstElt, !6 = $current, !7 = $childNode, !8 = $node
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '%0A%3C%21DOCTYPE+html%3E%0A%3Chtml+lang%3D%22fr%22%3E%0A%0A%3Chead%3E%0A++%3Cmeta+charset%3D%22UTF-8%22%3E%0A++%3Ctitle%3Etester+fusion%3C%2Ftitle%3E%0A++%3Cstyle%3E%0A++++span+%7Bcolor%3Ared%7D%0A++++.refid-valeur+%7Bwhite-space%3Anowrap%7D%0A++++.char-style-override-6+%7Bcolor%3Anavy%7D%0A++%3C%2Fstyle%3E%0A%3C%2Fhead%3E%0A%0A%3Cbody%3E%0A++%3Cdiv%3E%0A++++%3Cspan+class%3D%22refid-valeur+char-style-override-6%22%3Especial%3C%2Fspan%3E%3Cspan+class%3D%22refid-valeur+char-style-override-6%22%3E+%3C%2Fspan%3E%3Cspan+class%3D%22refid-valeur+char-style-override-6%22%3Eespace%3C%2Fspan%3E%0A++%3C%2Fdiv%3E%0A++%3Cspan+class%3D%22refid-valeur+char-style-override-6%22%3ERCR-ART-RCR-L%3C%2Fspan%3E%3Cspan+class%3D%22refid-valeur+char-style-override-6%22%3E213%3C%2Fspan%3E%3Cspan+class%3D%22refid-valeur+char-style-override-6%22%3E-1%3C%2Fspan%3E%0A++%3Cdiv%3E%0A++++%3Cspan+class%3D%22refid-valeur+char-style-override-6%22%3Es%C3%A9quence+avec+child%3C%2Fspan%3E%3Cspan+class%3D%22refid-valeur+char-style-override-6%22%3E+P%3Cspan%3EA%3C%2Fspan%3ES%3C%2Fspan%3E%3Cspan+class%3D%22refid-valeur+char-style-override-6%22%3E+%3C%2Fspan%3E%3Cspan+class%3D%22refid-valeur+char-style-override-6%22%3E%3Cem%3ED%3C%2Fem%3EE+PRO%3C%2Fspan%3E%3Cspan+class%3D%22refid-valeur+char-style-override-6%22%3EBL%C3%88ME%3C%2Fspan%3E%3Cspan+class%3D%22refid-valeur+char-style-override-6%22%3E+%3Cstrong%3EICI%3C%2Fstrong%3E%3F%3C%2Fspan%3E%0A++%3C%2Fdiv%3E%0A%3C%2Fbody%3E%0A%0A%3C%2Fhtml%3E%0A'
   30     1        NEW                                                  $10     'DOMDocument'
          2        DO_FCALL                                          0          
          3        ASSIGN                                                       !1, $10
   31     4        INIT_METHOD_CALL                                             !1, 'loadHTML'
          5        SEND_VAR_EX                                                  !0
          6        SEND_VAL_EX                                                  8196
          7        DO_FCALL                                          0          
   32     8        NEW                                                  $14     'DOMXPath'
          9        SEND_VAR_EX                                                  !1
         10        DO_FCALL                                          0          
         11        ASSIGN                                                       !2, $14
   34    12        INIT_METHOD_CALL                                             !2, 'query'
   39    13        SEND_VAL_EX                                                  '%2F%2Fspan%5B%40class%3D%22refid-valeur+char-style-override-6%22%5D%5Bnot%28preceding-sibling%3A%3Anode%28%29%5B1%5D%5Blocal-name%28%29%3D%22span%22%5D%5B%40class%3D%22refid-valeur+char-style-override-6%22%5D%29%5D%5Bfollowing-sibling%3A%3Anode%28%29%5B1%5D%5Blocal-name%28%29%3D%22span%22%5D%5B%40class%3D%22refid-valeur+char-style-override-6%22%5D%5D'
   34    14        DO_FCALL                                          0  $17     
         15        ASSIGN                                                       !3, $17
   57    16        ASSIGN                                                       !4, <array>
   59    17      > FE_RESET_R                                           $20     !3, ->43
         18    > > FE_FETCH_R                                                   $20, !5, ->43
   61    19    >   ASSIGN                                                       !6, !5
   63    20      > JMP                                                          ->38
   64    21    >   INIT_FCALL                                                   'issameelt'
         22        SEND_VAR                                                     !5
         23        SEND_VAR                                                     !6
         24        DO_FCALL                                          0  $22     
         25        BOOL_NOT                                             ~23     $22
         26      > JMPZ                                                         ~23, ->28
   65    27    > > JMP                                                          ->42
   67    28    >   FETCH_OBJ_R                                          ~24     !6, 'childNodes'
         29      > FE_RESET_R                                           $25     ~24, ->35
         30    > > FE_FETCH_R                                                   $25, !7, ->35
   68    31    >   INIT_METHOD_CALL                                             !5, 'appendChild'
         32        SEND_VAR_EX                                                  !7
         33        DO_FCALL                                          0          
   67    34      > JMP                                                          ->30
         35    >   FE_FREE                                                      $25
   70    36        ASSIGN_DIM                                                   !4
         37        OP_DATA                                                      !6
   63    38    >   FETCH_OBJ_R                                          ~28     !6, 'nextSibling'
         39        ASSIGN                                               ~29     !6, ~28
         40        TYPE_CHECK                                      1020          ~29
         41      > JMPNZ                                                        ~30, ->21
   59    42    > > JMP                                                          ->18
         43    >   FE_FREE                                                      $20
   74    44      > FE_RESET_R                                           $31     !4, ->51
         45    > > FE_FETCH_R                                                   $31, !8, ->51
   75    46    >   FETCH_OBJ_R                                          ~32     !8, 'parentNode'
         47        INIT_METHOD_CALL                                             ~32, 'removeChild'
         48        SEND_VAR_EX                                                  !8
         49        DO_FCALL                                          0          
   74    50      > JMP                                                          ->45
         51    >   FE_FREE                                                      $31
   78    52        INIT_METHOD_CALL                                             !1, 'saveHTML'
         53        DO_FCALL                                          0  $34     
         54        ECHO                                                         $34
         55      > RETURN                                                       1

Function issameelt:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 14
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 36
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 36
Branch analysis from position: 17
2 jumps found. (Code = 47) Position 1 = 24, Position 2 = 32
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 35
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 32
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
filename:       /in/O1UNq
function name:  isSameElt
number of ops:  39
compiled vars:  !0 = $node1, !1 = $node2, !2 = $attr
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   42     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   43     2        FETCH_OBJ_R                                          ~3      !0, 'nodeName'
          3        FETCH_OBJ_R                                          ~4      !1, 'nodeName'
          4        IS_NOT_IDENTICAL                                             ~3, ~4
          5      > JMPZ                                                         ~5, ->7
   44     6    > > RETURN                                                       <false>
   46     7    >   FETCH_OBJ_R                                          ~6      !0, 'attributes'
          8        FETCH_OBJ_R                                          ~7      ~6, 'length'
          9        FETCH_OBJ_R                                          ~8      !1, 'attributes'
         10        FETCH_OBJ_R                                          ~9      ~8, 'length'
         11        IS_NOT_IDENTICAL                                             ~7, ~9
         12      > JMPZ                                                         ~10, ->14
   47    13    > > RETURN                                                       <false>
   49    14    >   FETCH_OBJ_R                                          ~11     !0, 'attributes'
         15      > FE_RESET_R                                           $12     ~11, ->36
         16    > > FE_FETCH_R                                                   $12, !2, ->36
   50    17    >   INIT_METHOD_CALL                                             !1, 'hasAttribute'
         18        CHECK_FUNC_ARG                                               
         19        FETCH_OBJ_FUNC_ARG                                   $13     !2, 'name'
         20        SEND_FUNC_ARG                                                $13
         21        DO_FCALL                                          0  $14     
         22        BOOL_NOT                                             ~15     $14
         23      > JMPNZ_EX                                             ~15     ~15, ->32
         24    >   INIT_METHOD_CALL                                             !1, 'getAttribute'
         25        CHECK_FUNC_ARG                                               
         26        FETCH_OBJ_FUNC_ARG                                   $16     !2, 'name'
         27        SEND_FUNC_ARG                                                $16
         28        DO_FCALL                                          0  $17     
         29        FETCH_OBJ_R                                          ~18     !2, 'value'
         30        IS_NOT_IDENTICAL                                     ~19     $17, ~18
         31        BOOL                                                 ~15     ~19
         32    > > JMPZ                                                         ~15, ->35
   51    33    >   FE_FREE                                                      $12
         34      > RETURN                                                       <false>
   49    35    > > JMP                                                          ->16
         36    >   FE_FREE                                                      $12
   53    37      > RETURN                                                       <true>
   54    38*     > RETURN                                                       null

End of function issameelt

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
158.01 ms | 2346 KiB | 14 Q