PHP - 删除重复的音节词 [英] PHP - remove duplicate syllable word

查看:113
本文介绍了PHP - 删除重复的音节词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的,想知道如何在php中使用正则表达式。
如果我有文字像hahaabcabcabchehehecupcupcupcup(包含重复的音节词)。

i'm new and wanna know how to using regex in php. if i have text like "haha" "abcabcabc" "hehehe" "cupcupcupcup" (contain duplicate of syllable word).

如何删除该文本?

(说 $ text =cupcupcup; ,如何使这样像 $ text =;

(say $text="cupcupcup";", how to make this like $text="";)

对不起,如果有同样问题(我有搜索,但不能找到描述我的问题的页面)

sorry if there is same ask (i have search, but cant find page that describe my issue)

感谢您的赞赏:)

推荐答案

尝试

$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"

这篇关于PHP - 删除重复的音节词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆