Page 1 of 1

no spaces

Posted: Mon May 09, 2005 11:52 am
by phpScott
I am trying to just remove spaces from a string I though

Code: Select all

$string = "some text here";
$path = preg_replace('/\s\s+/', ' ', $string);
would take care of it but alas no.
is still get

Code: Select all

echo $string;
//some text here

//when i would like

//sometexthere
if one of you regex whiz's could help that would be super-smooth.

thanks

Posted: Mon May 09, 2005 12:02 pm
by Chris Corbyn
You should be aware that \s takes out ALL whitespace (including carriage returns).

But anyhow

Code: Select all

$string = "some text here";
$space_free = preg_replace('/\s+/', '', $string);
//sometexthere
If don't want to take out carriage returns and tabs then don't take the regex route.... a simple str_replace() would make more sense then ;-)

EDIT | I see you echo'd $string in your version (that's the original string).

Posted: Mon May 09, 2005 12:34 pm
by phpScott
thanks, know i know why your incharge of the regex forumns.

dope. that was a cut paste thing that I forgot to change to make right.

Posted: Mon May 09, 2005 5:29 pm
by Skara
.. there's really no need for a regex here, though.

Code: Select all

$string = str_replace(' ','',$string);
should work fine.