3v4l.org

run code in 300+ PHP versions simultaneously
<?php $textbody = " <ul> List item 1 List item 2 List item 3 </ul> "; $content = new DOMDocument(); $content->loadHTML($textbody); $content = new DOMDocument(); //get DOMNodeList $ulList = $content->getElementsByTagName("ul"); //loop DOMNodeList to get nodes foreach ( $ulList as $ul ) { //get the lines between <ul> $lines = explode("\n",$ul->firstChild->wholeText); //work on each line foreach ($lines as $line) { $newnode = $ul->appendChild($content->createElement('li',$line)); } } echo $textbody = $content->saveHTML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 36
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 36
Branch analysis from position: 16
2 jumps found. (Code = 77) Position 1 = 24, Position 2 = 34
Branch analysis from position: 24
2 jumps found. (Code = 78) Position 1 = 25, Position 2 = 34
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 34
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
filename:       /in/nbnRO
function name:  (null)
number of ops:  42
compiled vars:  !0 = $textbody, !1 = $content, !2 = $ulList, !3 = $ul, !4 = $lines, !5 = $line, !6 = $newnode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%0A%3Cul%3E%0AList+item+1%0AList+item+2%0AList+item+3%0A%3C%2Ful%3E%0A'
   10     1        NEW                                              $8      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $8
   11     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   12     7        NEW                                              $12     'DOMDocument'
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !1, $12
   14    10        INIT_METHOD_CALL                                         !1, 'getElementsByTagName'
         11        SEND_VAL_EX                                              'ul'
         12        DO_FCALL                                      0  $15     
         13        ASSIGN                                                   !2, $15
   17    14      > FE_RESET_R                                       $17     !2, ->36
         15    > > FE_FETCH_R                                               $17, !3, ->36
   19    16    >   INIT_FCALL                                               'explode'
         17        SEND_VAL                                                 '%0A'
         18        FETCH_OBJ_R                                      ~18     !3, 'firstChild'
         19        FETCH_OBJ_R                                      ~19     ~18, 'wholeText'
         20        SEND_VAL                                                 ~19
         21        DO_ICALL                                         $20     
         22        ASSIGN                                                   !4, $20
   21    23      > FE_RESET_R                                       $22     !4, ->34
         24    > > FE_FETCH_R                                               $22, !5, ->34
   22    25    >   INIT_METHOD_CALL                                         !3, 'appendChild'
         26        INIT_METHOD_CALL                                         !1, 'createElement'
         27        SEND_VAL_EX                                              'li'
         28        SEND_VAR_EX                                              !5
         29        DO_FCALL                                      0  $23     
         30        SEND_VAR_NO_REF_EX                                       $23
         31        DO_FCALL                                      0  $24     
         32        ASSIGN                                                   !6, $24
   21    33      > JMP                                                      ->24
         34    >   FE_FREE                                                  $22
   17    35      > JMP                                                      ->15
         36    >   FE_FREE                                                  $17
   25    37        INIT_METHOD_CALL                                         !1, 'saveHTML'
         38        DO_FCALL                                      0  $26     
         39        ASSIGN                                           ~27     !0, $26
         40        ECHO                                                     ~27
         41      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
204.93 ms | 1400 KiB | 15 Q