tomtimms Posted April 6, 2010 Share Posted April 6, 2010 I am trying to remove all the white space before and after a comma. So if I have ( Bob Thomas,Bill Sampson , Ted Ginn , Greg Mood ) it would then become (Bob Thomas,Bill Sampson,Ted Ginn,Greg Mood). I have tried using TRIM however that removed white space before and after the string. Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 6, 2010 Share Posted April 6, 2010 preg_replace() to the rescue: $text = "Bob Thomas,Bill Sampson , Ted Ginn , Greg Mood"; $newText = preg_replace("/\s*,\s*/", ",", $text); echo $newText . "<br>"; //Output: Bob Thomas,Bill Sampson,Ted Ginn,Greg Mood Quote Link to comment Share on other sites More sharing options...
tomtimms Posted April 6, 2010 Author Share Posted April 6, 2010 Thanks, I actually tried using preg_replace before however I couldn't get the pattern right....seems like you were able to show me what I was missing...Thanks a ton! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.