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.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to