Re: Remove Spaces from Middle of String

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If you have this, it's better:
$data = preg_replace("/  /", $data);
You may want to consider "/\\s+/" if you want newlines to be collapsed
in as well.

If preg_replace is not in your PHP, so you gotta use str_replace, then
strstr is better to find the '  ' because it's probably slightly
faster than preg_match()

I suspect preg_replace() is available everywhere preg_match() is
available, but will not swear to it.

On Tue, October 3, 2006 1:08 pm, Kevin Murphy wrote:
> This works, but I was wondering if this was the best way to
> accomplish this or not. I'm trying to remove any extra spaces (not
> whitespace like carriage returns) from the middle of a string....
> mainly for times where people put extra spaces after periods in
> paragraph.
>
> 	while(preg_match('/  /',$data))
> 	{	$data = str_replace("  "," ",$data);	}
>
> Is there a better way to accomplish this same task? (PHP 4.x). Thanks.
>
>
> --
> Kevin Murphy
> Webmaster: Information and Marketing Services
> Western Nevada Community College
> www.wncc.edu
> 775-445-3326
>
>
>


-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux