#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    18
    Rep Power
    0
    I am in search of a way to format a string in php to not have more than one space between words. (I have already taken care of trimming the spaces at the front and back of the string.)

    example:

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>"Blue Dog Cat and Door"[/code]

    needs to be changed to:

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>"Blue Dog Cat and Door"[/code]

    any help would be greatly appreciated!

    Mike

    [This message has been edited by qweqwe (edited July 26, 2000).]
  2. #2
  3. No Profile Picture
    RyanP
    Guest
    Devshed Newbie (0 - 499 posts)
    hi qweqwe,
    i think that you want to use a regular expression to search for 1 or more whitespace characters and then replace them with one space

    $var = preg_replace("/s+/", " ", $var);
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Seaside, CA
    Posts
    84
    Rep Power
    14
    You could also use the MySQL or PHP trim() function.

    ------------------
    From the day we're born, we're running out of time.
  6. #4
  7. No Profile Picture
    RyanP
    Guest
    Devshed Newbie (0 - 499 posts)
    Joel: Doesn't trim() only remove leading and trailing whitespaces? I believe that qweqwe wishes to remove whitespaces inside of a string, not on the edges.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    18
    Rep Power
    0
    The regular experssion was what I needed, Thank you RyanP. I have only used reg. exp. with PERL so I didnt know the syntax, but what you gave me works great! Thanks!

    Thanks Joel, I am already using trim() to cut off spaces on front and back of string.

    Mike
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Seaside, CA
    Posts
    84
    Rep Power
    14
    Yep. My mistake, qweqwe. Didn't read your qualifier in parentheses. Guess I've been up a little too long today.

Similar Threads

  1. Replies: 1
    Last Post: November 24th, 2003, 06:46 PM
  2. Replacing spaces with %20
    By Antixat in forum Linux Help
    Replies: 1
    Last Post: September 9th, 2003, 04:47 PM
  3. Replacing _ with spaces
    By jamesf4218 in forum PHP Development
    Replies: 6
    Last Post: July 1st, 2003, 08:21 AM

IMN logo majestic logo threadwatch logo seochat tools logo