(PHP) Regex for trimming whitespace

 

  1. function trim_whitespace($source)
  2.   {
  3.     $pattern = ‘/[^\w]\s*/’;
  4.     return preg_replace($pattern, ‘ ‘, $source);
  5.   }
This entry was posted in PHP and tagged , , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Why ask?

  • Advertisement

  • Categories