Skip to content
Advertisement

Replacing x or more dots

I want a clean solution to replace dots in text:

Some title…. to this: Some title…

Some…. title…… to this: Some… title…

How can I replace every sequence of more than 3 dots with 3 dots?

Advertisement

Answer

With a regular expression based search and replaceDocs:

$text = preg_replace('/.{4,}/', '...', $text);

The pattern says: Match four or more dots ., the second parameter is the replacement.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement