3v4l.org

run code in 500+ PHP versions simultaneously
<?php $filedata = <<<EOT <?xml version="1.0" encoding="utf-8" ?> <article xmlns="http://docbook.org/ns/docbook" version="5.0" xmlns:xlink="http://www.w3.org/1999/xlink" > <para> This is an <emphasis role="strong">hello <em>world</em></emphasis> sentence. </para> </article> EOT; $dom = new DOMDocument(); $dom->loadXML($filedata); foreach($dom->documentElement->childNodes as $node){ if(XML_ELEMENT_NODE === $node->nodeType && 'para' === $node->nodeName){ // Replace any emphasis elements foreach($node->childNodes as $childNode) { if(XML_ELEMENT_NODE === $childNode->nodeType && 'emphasis' === $childNode->nodeName){ // This is arguably the most "correct" way to replace, just in case // there's extra nodes inside. A cheaper way would be to not loop // and just use the nodeValue however you might lose some HTML. $newNode = $dom->createElement('b'); foreach($childNode->childNodes as $grandChild){ $newNode->appendChild($grandChild->cloneNode(true)); } $childNode->replaceWith($newNode); } } // Build our output $output = ''; foreach($node->childNodes as $childNode) { $output .= $dom->saveHTML($childNode); } // The provided XML has a namespace, and when cloning nodes that NS comes // along. Since we are going from regular XML to irregular HTML I think // a string replacement is best. $output = str_replace(' xmlns="http://docbook.org/ns/docbook"', '', $output); echo $output; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 63
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 63
Branch analysis from position: 11
2 jumps found. (Code = 46) Position 1 = 14, Position 2 = 17
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 62
Branch analysis from position: 18
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 47
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 47
Branch analysis from position: 21
2 jumps found. (Code = 46) Position 1 = 24, Position 2 = 27
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 46
Branch analysis from position: 28
2 jumps found. (Code = 77) Position 1 = 34, Position 2 = 42
Branch analysis from position: 34
2 jumps found. (Code = 78) Position 1 = 35, Position 2 = 42
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 42
Branch analysis from position: 46
Branch analysis from position: 27
Branch analysis from position: 47
2 jumps found. (Code = 77) Position 1 = 51, Position 2 = 57
Branch analysis from position: 51
2 jumps found. (Code = 78) Position 1 = 52, Position 2 = 57
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 57
Branch analysis from position: 47
Branch analysis from position: 62
Branch analysis from position: 17
Branch analysis from position: 63
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 63
filename:       /in/04Tc3
function name:  (null)
number of ops:  65
compiled vars:  !0 = $filedata, !1 = $dom, !2 = $node, !3 = $childNode, !4 = $newNode, !5 = $grandChild, !6 = $output
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '%3C%3Fxml+version%3D%221.0%22+encoding%3D%22utf-8%22+%3F%3E%0A%3Carticle%0A++xmlns%3D%22http%3A%2F%2Fdocbook.org%2Fns%2Fdocbook%22+version%3D%225.0%22%0A++xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22+%3E%0A%3Cpara%3E%0AThis+is+an+%3Cemphasis+role%3D%22strong%22%3Ehello+%3Cem%3Eworld%3C%2Fem%3E%3C%2Femphasis%3E+sentence.%0A%3C%2Fpara%3E%0A%3C%2Farticle%3E'
   14     1        NEW                                                  $8      'DOMDocument'
          2        DO_FCALL                                          0          
          3        ASSIGN                                                       !1, $8
   15     4        INIT_METHOD_CALL                                             !1, 'loadXML'
          5        SEND_VAR_EX                                                  !0
          6        DO_FCALL                                          0          
   17     7        FETCH_OBJ_R                                          ~12     !1, 'documentElement'
          8        FETCH_OBJ_R                                          ~13     ~12, 'childNodes'
          9      > FE_RESET_R                                           $14     ~13, ->63
         10    > > FE_FETCH_R                                                   $14, !2, ->63
   18    11    >   FETCH_OBJ_R                                          ~15     !2, 'nodeType'
         12        IS_IDENTICAL                                         ~16     ~15, 1
         13      > JMPZ_EX                                              ~16     ~16, ->17
         14    >   FETCH_OBJ_R                                          ~17     !2, 'nodeName'
         15        IS_IDENTICAL                                         ~18     ~17, 'para'
         16        BOOL                                                 ~16     ~18
         17    > > JMPZ                                                         ~16, ->62
   21    18    >   FETCH_OBJ_R                                          ~19     !2, 'childNodes'
         19      > FE_RESET_R                                           $20     ~19, ->47
         20    > > FE_FETCH_R                                                   $20, !3, ->47
   22    21    >   FETCH_OBJ_R                                          ~21     !3, 'nodeType'
         22        IS_IDENTICAL                                         ~22     ~21, 1
         23      > JMPZ_EX                                              ~22     ~22, ->27
         24    >   FETCH_OBJ_R                                          ~23     !3, 'nodeName'
         25        IS_IDENTICAL                                         ~24     ~23, 'emphasis'
         26        BOOL                                                 ~22     ~24
         27    > > JMPZ                                                         ~22, ->46
   27    28    >   INIT_METHOD_CALL                                             !1, 'createElement'
         29        SEND_VAL_EX                                                  'b'
         30        DO_FCALL                                          0  $25     
         31        ASSIGN                                                       !4, $25
   28    32        FETCH_OBJ_R                                          ~27     !3, 'childNodes'
         33      > FE_RESET_R                                           $28     ~27, ->42
         34    > > FE_FETCH_R                                                   $28, !5, ->42
   29    35    >   INIT_METHOD_CALL                                             !4, 'appendChild'
         36        INIT_METHOD_CALL                                             !5, 'cloneNode'
         37        SEND_VAL_EX                                                  <true>
         38        DO_FCALL                                          0  $29     
         39        SEND_VAR_NO_REF_EX                                           $29
         40        DO_FCALL                                          0          
   28    41      > JMP                                                          ->34
         42    >   FE_FREE                                                      $28
   31    43        INIT_METHOD_CALL                                             !3, 'replaceWith'
         44        SEND_VAR_EX                                                  !4
         45        DO_FCALL                                          0          
   21    46    > > JMP                                                          ->20
         47    >   FE_FREE                                                      $20
   36    48        ASSIGN                                                       !6, ''
   37    49        FETCH_OBJ_R                                          ~33     !2, 'childNodes'
         50      > FE_RESET_R                                           $34     ~33, ->57
         51    > > FE_FETCH_R                                                   $34, !3, ->57
   38    52    >   INIT_METHOD_CALL                                             !1, 'saveHTML'
         53        SEND_VAR_EX                                                  !3
         54        DO_FCALL                                          0  $35     
         55        ASSIGN_OP                                         8          !6, $35
   37    56      > JMP                                                          ->51
         57    >   FE_FREE                                                      $34
   44    58        FRAMELESS_ICALL_3                str_replace         ~37     '+xmlns%3D%22http%3A%2F%2Fdocbook.org%2Fns%2Fdocbook%22', ''
         59        OP_DATA                                                      !6
         60        ASSIGN                                                       !6, ~37
   45    61        ECHO                                                         !6
   17    62    > > JMP                                                          ->10
         63    >   FE_FREE                                                      $14
   47    64      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
164.24 ms | 1894 KiB | 13 Q