PHP remove (conditional) duplicate row in text -
$string = "apple foo banana ... banana foo other text ... apple"; i have text single rows duplicated after row "...".
the rows before , after can ("foo"), duplicate (without "..." "apple").
the "..."-row can appear multiple times without duplicate row after it.
i want remove duplicated rows have "..." row inbetween.
in other words: remove line after "..." if it's same above "..."
how can match
banana ... banana to remove duplicated row:
banana so result is
$string = "apple foo banana ... foo other text ... apple"; cheers!
if task remove line following line 3 dots:
echo preg_replace("/^(.+?)\r?\n(\.{3})\r?\n\\1/m", "\\1\n\\2", $string); the expression matches:
- a whole line comprising @ least 1 character (1)
- three dots on single line (2)
- a whole line comprising @ least 1 character (1)
the /m modifier used select multi-line mode, in ^ , $ carry meaning of start , end of line.
the \\1 reference used match whatever before 3 dots.
the replacement '\\1' needed place matched line 3 dots.
Comments
Post a Comment