PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Fri Nov 22, 2019 2:21 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: no spaces
PostPosted: Mon May 09, 2005 11:52 am 
Offline
DevNet Resident
User avatar

Joined: Wed Oct 09, 2002 6:51 pm
Posts: 1206
Location: Keele, U.K.
I am trying to just remove spaces from a string I though
Syntax: [ Download ] [ Hide ]
$string = "some text here";

$path = preg_replace('/\s\s+/', ' ', $string);

would take care of it but alas no.
is still get

Syntax: [ Download ] [ Hide ]
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 09, 2005 12:02 pm 
Offline
Breakbeat Nuttzer
User avatar

Joined: Wed Mar 24, 2004 8:57 am
Posts: 13098
Location: Melbourne, Australia
You should be aware that \s takes out ALL whitespace (including carriage returns).

But anyhow

Syntax: [ Download ] [ Hide ]
$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).


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 09, 2005 12:34 pm 
Offline
DevNet Resident
User avatar

Joined: Wed Oct 09, 2002 6:51 pm
Posts: 1206
Location: Keele, U.K.
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.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 09, 2005 5:29 pm 
Offline
Forum Regular
User avatar

Joined: Sat Mar 12, 2005 8:13 pm
Posts: 703
Location: US
.. there's really no need for a regex here, though.
Syntax: [ Download ] [ Hide ]
$string = str_replace(' ','',$string);

should work fine.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group