3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = '<ul><li><a href="test.php">Test</a>(10)</li></ul>'; echo $string; $dom_document = new DOMDocument(); $dom_document->loadHTML($string); $new_string = ""; foreach($dom_document->getElementsByTagName('ul') as $ul){ // For all ul. $new_string .= "<ul>"; foreach($ul->childNodes as $li){ // For all li. $new_string .= "<li>"; $i=0; foreach($li->childNodes as $a){ if(isset($a->attributes[0]->value)){ $href = $a->attributes[0]->value; } if($i===0){ $new_string .= '<a href="'.$href.'">'; } $new_string .= $a->nodeValue; $i++; } $new_string .= "</a>"; $new_string .= "</li>"; } $new_string .= "</ul>"; } echo $new_string;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 47
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 47
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 44
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 44
Branch analysis from position: 18
2 jumps found. (Code = 77) Position 1 = 22, Position 2 = 40
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 40
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 31
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 36
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 36
Branch analysis from position: 31
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 40
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 44
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
filename:       /in/pWLiL
function name:  (null)
number of ops:  50
compiled vars:  !0 = $string, !1 = $dom_document, !2 = $new_string, !3 = $ul, !4 = $li, !5 = $i, !6 = $a, !7 = $href
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Cul%3E%3Cli%3E%3Ca+href%3D%22test.php%22%3ETest%3C%2Fa%3E%2810%29%3C%2Fli%3E%3C%2Ful%3E'
    5     1        ECHO                                                     !0
    7     2        NEW                                              $9      'DOMDocument'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $9
    9     5        INIT_METHOD_CALL                                         !1, 'loadHTML'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0          
   11     8        ASSIGN                                                   !2, ''
   12     9        INIT_METHOD_CALL                                         !1, 'getElementsByTagName'
         10        SEND_VAL_EX                                              'ul'
         11        DO_FCALL                                      0  $14     
         12      > FE_RESET_R                                       $15     $14, ->47
         13    > > FE_FETCH_R                                               $15, !3, ->47
   13    14    >   ASSIGN_OP                                     8          !2, '%3Cul%3E'
   14    15        FETCH_OBJ_R                                      ~17     !3, 'childNodes'
         16      > FE_RESET_R                                       $18     ~17, ->44
         17    > > FE_FETCH_R                                               $18, !4, ->44
   15    18    >   ASSIGN_OP                                     8          !2, '%3Cli%3E'
   16    19        ASSIGN                                                   !5, 0
   17    20        FETCH_OBJ_R                                      ~21     !4, 'childNodes'
         21      > FE_RESET_R                                       $22     ~21, ->40
         22    > > FE_FETCH_R                                               $22, !6, ->40
   18    23    >   FETCH_OBJ_IS                                     ~23     !6, 'attributes'
         24        FETCH_DIM_IS                                     ~24     ~23, 0
         25        ISSET_ISEMPTY_PROP_OBJ                                   ~24, 'value'
         26      > JMPZ                                                     ~25, ->31
   19    27    >   FETCH_OBJ_R                                      ~26     !6, 'attributes'
         28        FETCH_DIM_R                                      ~27     ~26, 0
         29        FETCH_OBJ_R                                      ~28     ~27, 'value'
         30        ASSIGN                                                   !7, ~28
   21    31    >   IS_IDENTICAL                                             !5, 0
         32      > JMPZ                                                     ~30, ->36
   22    33    >   CONCAT                                           ~31     '%3Ca+href%3D%22', !7
         34        CONCAT                                           ~32     ~31, '%22%3E'
         35        ASSIGN_OP                                     8          !2, ~32
   24    36    >   FETCH_OBJ_R                                      ~34     !6, 'nodeValue'
         37        ASSIGN_OP                                     8          !2, ~34
   25    38        PRE_INC                                                  !5
   17    39      > JMP                                                      ->22
         40    >   FE_FREE                                                  $22
   27    41        ASSIGN_OP                                     8          !2, '%3C%2Fa%3E'
   28    42        ASSIGN_OP                                     8          !2, '%3C%2Fli%3E'
   14    43      > JMP                                                      ->17
         44    >   FE_FREE                                                  $18
   30    45        ASSIGN_OP                                     8          !2, '%3C%2Ful%3E'
   12    46      > JMP                                                      ->13
         47    >   FE_FREE                                                  $15
   33    48        ECHO                                                     !2
         49      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.45 ms | 1399 KiB | 13 Q