3v4l.org

run code in 300+ PHP versions simultaneously
<?php function isLi($line) { return strstr($line, '<li'); } $text = 'Some text <strong>Some other text</strong> <li>Element A1</li><li>Element A2</li> <li>Element A3</li> Text that separates group A from group B <li>Element B1</li> <li>Element B2</li> <li>Element B3</li> <li>Element B4</li> <strong>Element that separates group B from group C</strong> <li>Element C1</li> <li>Element C2</li> Text can follow. <li>Hello, nothing follows this</li>'; $array = explode("\n", $text); $html = ''; $previousWasLi = false; foreach ($array as $line) { if (empty($line)) { continue; } if (isLi($line) && $previousWasLi == false) { $html .= "<ul>\n"; $html .= $line ."\n"; $previousWasLi = true; } elseif (isLi($line) && $previousWasLi == true) { $html .= $line ."\n"; $previousWasLi = true; } elseif (!isLi($line) && $previousWasLi == true) { $html .= "</ul>\n"; $html .= $line ."\n"; $previousWasLi = false; } elseif (!isLi($line) && $previousWasLi == false) { $html .= $line ."\n"; } } // if the last line was an li, we need to close the ul if ($previousWasLi) { $html .= '</ul>'; } echo $html;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 60
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 60
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 13
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 13
2 jumps found. (Code = 46) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 25
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 25
2 jumps found. (Code = 46) Position 1 = 29, Position 2 = 31
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 36
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
Branch analysis from position: 36
2 jumps found. (Code = 46) Position 1 = 41, Position 2 = 43
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 49
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
Branch analysis from position: 49
2 jumps found. (Code = 46) Position 1 = 54, Position 2 = 56
Branch analysis from position: 54
2 jumps found. (Code = 43) Position 1 = 57, Position 2 = 59
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 59
Branch analysis from position: 56
Branch analysis from position: 43
Branch analysis from position: 31
Branch analysis from position: 19
Branch analysis from position: 60
2 jumps found. (Code = 43) Position 1 = 62, Position 2 = 63
Branch analysis from position: 62
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 63
Branch analysis from position: 60
filename:       /in/kmfee
function name:  (null)
number of ops:  65
compiled vars:  !0 = $text, !1 = $array, !2 = $html, !3 = $previousWasLi, !4 = $line
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   ASSIGN                                                   !0, 'Some+text%0A%3Cstrong%3ESome+other+text%3C%2Fstrong%3E%0A%3Cli%3EElement+A1%3C%2Fli%3E%3Cli%3EElement+A2%3C%2Fli%3E%0A%3Cli%3EElement+A3%3C%2Fli%3E%0AText+that+separates+group+A+from+group+B%0A%3Cli%3EElement+B1%3C%2Fli%3E%0A%0A%3Cli%3EElement+B2%3C%2Fli%3E+%3Cli%3EElement+B3%3C%2Fli%3E%0A%3Cli%3EElement+B4%3C%2Fli%3E%0A%3Cstrong%3EElement+that+separates+group+B+from+group+C%3C%2Fstrong%3E%0A%3Cli%3EElement+C1%3C%2Fli%3E%0A%3Cli%3EElement+C2%3C%2Fli%3E%0AText+can+follow.%0A%3Cli%3EHello%2C+nothing+follows+this%3C%2Fli%3E'
   22     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '%0A'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $6      
          5        ASSIGN                                                   !1, $6
   24     6        ASSIGN                                                   !2, ''
   25     7        ASSIGN                                                   !3, <false>
   27     8      > FE_RESET_R                                       $10     !1, ->60
          9    > > FE_FETCH_R                                               $10, !4, ->60
   28    10    >   ISSET_ISEMPTY_CV                                         !4
         11      > JMPZ                                                     ~11, ->13
   29    12    > > JMP                                                      ->9
   31    13    >   INIT_FCALL                                               'isli'
         14        SEND_VAR                                                 !4
         15        DO_FCALL                                      0  $12     
         16      > JMPZ_EX                                          ~13     $12, ->19
         17    >   BOOL_NOT                                         ~14     !3
         18        BOOL                                             ~13     ~14
         19    > > JMPZ                                                     ~13, ->25
   32    20    >   ASSIGN_OP                                     8          !2, '%3Cul%3E%0A'
   33    21        CONCAT                                           ~16     !4, '%0A'
         22        ASSIGN_OP                                     8          !2, ~16
   34    23        ASSIGN                                                   !3, <true>
         24      > JMP                                                      ->59
   35    25    >   INIT_FCALL                                               'isli'
         26        SEND_VAR                                                 !4
         27        DO_FCALL                                      0  $19     
         28      > JMPZ_EX                                          ~20     $19, ->31
         29    >   BOOL                                             ~21     !3
         30        BOOL                                             ~20     ~21
         31    > > JMPZ                                                     ~20, ->36
   36    32    >   CONCAT                                           ~22     !4, '%0A'
         33        ASSIGN_OP                                     8          !2, ~22
   37    34        ASSIGN                                                   !3, <true>
         35      > JMP                                                      ->59
   38    36    >   INIT_FCALL                                               'isli'
         37        SEND_VAR                                                 !4
         38        DO_FCALL                                      0  $25     
         39        BOOL_NOT                                         ~26     $25
         40      > JMPZ_EX                                          ~26     ~26, ->43
         41    >   BOOL                                             ~27     !3
         42        BOOL                                             ~26     ~27
         43    > > JMPZ                                                     ~26, ->49
   39    44    >   ASSIGN_OP                                     8          !2, '%3C%2Ful%3E%0A'
   40    45        CONCAT                                           ~29     !4, '%0A'
         46        ASSIGN_OP                                     8          !2, ~29
   41    47        ASSIGN                                                   !3, <false>
         48      > JMP                                                      ->59
   42    49    >   INIT_FCALL                                               'isli'
         50        SEND_VAR                                                 !4
         51        DO_FCALL                                      0  $32     
         52        BOOL_NOT                                         ~33     $32
         53      > JMPZ_EX                                          ~33     ~33, ->56
         54    >   BOOL_NOT                                         ~34     !3
         55        BOOL                                             ~33     ~34
         56    > > JMPZ                                                     ~33, ->59
   43    57    >   CONCAT                                           ~35     !4, '%0A'
         58        ASSIGN_OP                                     8          !2, ~35
   27    59    > > JMP                                                      ->9
         60    >   FE_FREE                                                  $10
   48    61      > JMPZ                                                     !3, ->63
   49    62    >   ASSIGN_OP                                     8          !2, '%3C%2Ful%3E'
   52    63    >   ECHO                                                     !2
   53    64      > RETURN                                                   1

Function isli:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kmfee
function name:  isLi
number of ops:  7
compiled vars:  !0 = $line
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'strstr'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 '%3Cli'
          4        DO_ICALL                                         $1      
          5      > RETURN                                                   $1
    5     6*     > RETURN                                                   null

End of function isli

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.91 ms | 1407 KiB | 21 Q