Jump to content

Archived

This topic is now archived and is closed to further replies.

climbjm

[SOLVED] replace regular expression for two or more spaces

Recommended Posts

I want to take any string of two or more spaces and replace it with one space.

[code]
$string = "          ";
$string = ereg_replace("\s\s*"," ",$string);
[/code]

you get the idea...

I have a valid reason for needing this, but it is too long to explain.

Share this post


Link to post
Share on other sites
I found what I was looking for...
$string = preg_replace("/(\s){2,}/i"," ",$string);
// gets rid of mutliple spaces and replaces it with one in the middle of a string.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.