Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想删除重复的字母(“tteeeessst stttringgg”=>“测试字符串”)。 php可以做到这一点吗?
尝试
$str = 'tteeeessst stttringgg'; echo preg_replace('{(.)\1+}','$1',$str);
演示
我假设你想删除重复的字母......这将删除像“字母”这样的单词,所以要小心......
$str = 'aabbccaaaaaddee'; echo preg_replace('{(.)\1+}','$1',$str); //abcade
来自http://randomdrake.com/2008/04/10/php-and-regex-replacing-repeating-characters-with-single-characters-in-a-string/