更新时间:2023-02-26 13:53:03
尝试
$txt = preg_replace("/^(.*)(\\1+)$/", "", $txt);
字符串的开始,然后匹配该字符串的至少一个重复,然后匹配字符串的末尾。
This searches for a sequence at the start of the string, then matches at least one repetition of that string, then matches the end of the string.
例如
$txt = preg_replace("/^(.*)(\\1+)$/", "", "cupcupcup"); //=> ""
$txt = preg_replace("/^(.*)(\\1+)$/", "", "cucupcup"); //=> "cucupcup"