Re: Removing WhiteSpace
| From: | phpme | Date: | Sun, 10 Sep 2000 13:52:16 +0000 |
| Subject: | Re: Removing WhiteSpace | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-16055@lists.php.net to get a copy of this message | ||
try these code:
<?php
$str="a b c d e f";
echo "<pre>$str</pre>";
$str=ereg_replace (" +"," ",$str);
echo "<pre>$str</pre>";
?>
On Sun, 10 Sep 2000 23:26:54 +1200
"Grant Walters" <Grant.Walters@walters.co.nz> wrote:
> > 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
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>