php - How to replace double/more letters to a single letter? -


i need convert letter occur twice or more within word single letter of itself.

for example:

school -> schol google -> gogle gooooogle -> gogle voodoo -> vodo 

i tried following, stuck @ second parameter in eregi_replace.

$word = 'goooogle'; $word2 = eregi_replace("([a-z]{2,})", "?", $word); 

if use \\\1 replace ?, display exact match. how make single letter?

can help? thanks

see regular expression replace 2 (or more) consecutive characters one?

by way: should use preg_* (pcre) functions instead of deprecated ereg_* functions (posix).

richard szalay's answer leads right way:

$word = 'goooogle'; $word2 = preg_replace('/(\w)\1+/', '$1', $word); 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -