Try
$txt = preg_replace("/^(.*)(\\1+)$/", "", $txt);
This searches for a sequence at the beginning of the line, then matches at least one repetition of that line, and then matches the end of the line.
eg.
$txt = preg_replace("/^(.*)(\\1+)$/", "", "cupcupcup"); //=> "" $txt = preg_replace("/^(.*)(\\1+)$/", "", "cucupcup"); //=> "cucupcup"
source share