SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    257
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Get rid of tabs and whitespace

    I have been trying to figure this out for hours but I cannot figure it out. I am trying to remove all extra whitespace between words and replace them with 1 space, also all tabs and line breaks so there is at maximum 1 space between words.

    Here is an example:

    Code:
     Last Login:  
    			    4/28/2006
    As you can see there is both whitespace and tabs between Last Login: and the actual login date.

    Does anyone know a regex or something that will replace all tabs and spaces line breaks with just 1 space at maximum?

  2. #2
    SitePoint Wizard dreamscape's Avatar
    Join Date
    Aug 2005
    Posts
    1,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try:
    PHP Code:
    preg_replace('/\s+/'' '$text); 

  3. #3
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    257
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That worked perfect! thank you!! I didnt think it was going to be that simple!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •