Jump to content


Photo

[SOLVED] replace regular expression for two or more spaces


  • Please log in to reply
1 reply to this topic

#1 climbjm

climbjm
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts
  • LocationSalt Lake City, UTAH

Posted 23 August 2006 - 07:15 AM

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

$string = "           ";
$string = ereg_replace("\s\s*"," ",$string);

you get the idea...

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

~ climbjm

#2 climbjm

climbjm
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts
  • LocationSalt Lake City, UTAH

Posted 23 August 2006 - 07:21 AM

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.

~ climbjm




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users