Re: how to replace many spaces with one space?

From: Date: Sun, 25 Oct 2009 19:59:58 +0000
Subject: Re: how to replace many spaces with one space?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-299328@lists.php.net to get a copy of this message
Jeffry Lunggot wrote:
Hi, how to replace many spaces in any string of character with one space? Regrads
Be careful about the word "spaces" do you mean exactly " "; or white spaces defined by "\s", which include spaces, tabs CRLFs. If you want specifically spaces and not all white spaces, then use "\x20" reg_replace("%\x20+%", " ", $str);//note the space between the quotes in the replace. If our string has CRLFs [i.e., newlines] then they will all will be reduced to
one. e.g., "     \n\n\n" will end up as " \n" if you use \s.
Also take into account the pattern modifier "m" (PCRE_MULTILINE). It may apply in your case.

« previous php.general (#299328) next »