Re: reduce all spaces to one [message #176900 is a reply to message #176898] |
Fri, 03 February 2012 20:19 |
M. Strobel
Messages: 386 Registered: December 2011
Karma:
|
Senior Member |
|
|
Am 03.02.2012 21:05, schrieb crankypuss:
> On 02/03/2012 12:36 PM, Jerry Stuckle wrote:
>> On 2/3/2012 2:03 PM, John wrote:
>>> Hello everybody,
>>>
>>> what would be in PHP the equivalent of the VB .NET statement
>>>
>>> Text = Regex.Replace(Text, "[ ]+", " ")
>>>
>>> in order to reduce to one all the spaces between words (chr(32)) ???
>>>
>>> Thanks for the hints.
>>>
>>>
>>
>> Try
>>
>> $text = preg_replace('/\s+/', ' ', $text);
>
> or,
>
> $text = str_replace(" ", " ", $text);
>
Solution shootout:
strobel@s114-intel:~> php -a
Interactive shell
php > echo str_replace(' ',' ','here are some spaces ');
here are some spaces
php > echo preg_replace('/\s+/', ' ', 'here are some spaces ');
here are some spaces
php >
The regex solution is the winner.
/Str.
|
|
|