3v4l.org

run code in 300+ PHP versions simultaneously
<?php $strings[] = '<p> Test string<br> </p> <p> <br> </p> <p> <br> </p>'; foreach($strings as $string){ // \s* matches any number of whitespace characters (" ", \t, \n, etc) // (?:...)+ matches one or more (without capturing the group) // $ forces match to only be made at the end of the string $string = preg_replace("/(?:<p>\s*(?:<br>\s*)+<\/p>\s*)+$/", "", $string); echo $string."\n---\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 13
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/gJTbK
function name:  (null)
number of ops:  15
compiled vars:  !0 = $strings, !1 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN_DIM                                               !0
          1        OP_DATA                                                  '%3Cp%3E+Test+string%3Cbr%3E+%3C%2Fp%3E+%3Cp%3E+%3Cbr%3E+%3C%2Fp%3E+%3Cp%3E+++%3Cbr%3E+%3C%2Fp%3E'
    5     2      > FE_RESET_R                                       $3      !0, ->13
          3    > > FE_FETCH_R                                               $3, !1, ->13
    9     4    >   INIT_FCALL                                               'preg_replace'
          5        SEND_VAL                                                 '%2F%28%3F%3A%3Cp%3E%5Cs%2A%28%3F%3A%3Cbr%3E%5Cs%2A%29%2B%3C%5C%2Fp%3E%5Cs%2A%29%2B%24%2F'
          6        SEND_VAL                                                 ''
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                         $4      
          9        ASSIGN                                                   !1, $4
   11    10        CONCAT                                           ~6      !1, '%0A---%0A'
         11        ECHO                                                     ~6
    5    12      > JMP                                                      ->3
         13    >   FE_FREE                                                  $3
   12    14      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.66 ms | 1386 KiB | 15 Q