How to strip excess whitespace from a string with preg_replace()

Add a comment August 7th, 2009

PHP provides many pre-defined methods to deal with strings. One of the strong way to deal with strings is to use regular expressions aka ‘regex‘.

Let’s use regular expression with preg_replace() method to strip excess whitespace from a string.

 

If you know any other alternative, please post in comments. I’ll add it in this article.

Share or Bookmark this Post:
  • StumbleUpon
  • Digg
  • Twitter
  • del.icio.us
  • Facebook
  • Mixx
  • MySpace
  • Reddit
  • Google Bookmarks
  • Yahoo! Buzz
  • Technorati
  • Live
  • DZone
  • Netvibes
  • RSS
  • Print

 

  1. August 9th, 2009 at 23:55 | #1

    Really cool tutorial! I Googled it but was unable to find a better way.

  1. No trackbacks yet.
Comments feed
Real Time Web Analytics