RE: [PHP] Removing WhiteSpace
| From: | Grant Walters | Date: | Sun, 10 Sep 2000 11:26:54 +0000 |
| Subject: | RE: [PHP] Removing WhiteSpace | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-16049@lists.php.net to get a copy of this message | ||
> the trim() functions should the trick
> http://www.php.net/manual/function.trim.php
>
Manual says "Strip whitespace from the beginning and end of a string"
I wish to replace duplicate spaces from the middle of the string with single
spaces, without evaluating every single portion added.
Something like the Unix sed command
sed -e 's/ * / /g'
is what I am trying to achieve
The above command would turn "A B C D E F" into "A B C D E F G"
>
> >
> >A bit lazy I guess, but I'm having trouble trying to replace multiple
> spaces
> >in a string.
> >
> >I'm concatenating variables from a form such as
> >$string=$Salutation.$First_Name.$Initial.$Surname
> >The string could be "Mr Grant Walters" and I want "Mr Grant Walters".
> >
> >I looked at preg_replace but don't really understand it. I keep getting
> >empty strings.
> >
Regards
GRANT WALTERS
Walters & Associates, P O Box 13-043, Johnsonville, Wellington, New Zealand
Phone: +64 4 4765175 CellPhone: 025 488265