Discover & Rate New Music Check out ChartVote. Promote the music you like.


Convert Multiple Spaces To a Single Space

Nifty line of PHP code that will take multiple sequential spaces and convert into a single space. This is great for cleaning and sanitizing data before storing it.

PHP:
  1. $date= preg_replace('/\s+/', ' ', $date);


One Comment

  1. Daniel Gattermann on August 8th, 2007

    Be careful substituting "\s" with a blank because a whitespace character can also be (e.g.) a newline or tab character ("\n" or "\t").
    Better use "\ +" (escaped blank) instead of "\s+" as it will only match multiple blanks and not newlines, etc.

Leave a Reply

RSS Feed



Recommended Sites