3v4l.org

run code in 300+ PHP versions simultaneously
<?php $strings[] = 'foo<p> <br> </p>'; $strings[] = 'foo<p> <br> </p>'; $strings[] = 'foo<p><br><br> </p>'; $strings[] = 'foo<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 = 9, Position 2 = 19
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 19
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/quoIe
function name:  (null)
number of ops:  21
compiled vars:  !0 = $strings, !1 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN_DIM                                               !0
          1        OP_DATA                                                  'foo%3Cp%3E%0A%0A%3Cbr%3E+%0A%3C%2Fp%3E'
    6     2        ASSIGN_DIM                                               !0
          3        OP_DATA                                                  'foo%3Cp%3E%0A+++++%3Cbr%3E+%0A%3C%2Fp%3E'
    9     4        ASSIGN_DIM                                               !0
          5        OP_DATA                                                  'foo%3Cp%3E%3Cbr%3E%3Cbr%3E+%0A%3C%2Fp%3E'
   11     6        ASSIGN_DIM                                               !0
          7        OP_DATA                                                  'foo%3Cp%3E%0A+%3Cbr%3E+%0A%3C%2Fp%3E'
   15     8      > FE_RESET_R                                       $6      !0, ->19
          9    > > FE_FETCH_R                                               $6, !1, ->19
   19    10    >   INIT_FCALL                                               'preg_replace'
         11        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'
         12        SEND_VAL                                                 ''
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                         $7      
         15        ASSIGN                                                   !1, $7
   21    16        CONCAT                                           ~9      !1, '%0A---%0A'
         17        ECHO                                                     ~9
   15    18      > JMP                                                      ->9
         19    >   FE_FREE                                                  $6
   22    20      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.12 ms | 1395 KiB | 15 Q