remove spaces and + symbols

Hi,
I have a string from php parameter which I need the get rid of all the spaces and + symbols  

for example I need the 2 words from this stored in separate variables

'fred++++nurk+'
jagguyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobOwner (Aidellio)Commented:
var s = "Fred++++nurk+";
var t = s.replace(/(+)+/g,"+");
var terms = t.split("+");

terms[0] is "Fred"
terms[1] is "nurk"
0
RobOwner (Aidellio)Commented:
http://jsbin.com/kabizopugu/1/edit

slight edit on the replace:

.replace(/(\+)+/g,"+")
0
RobOwner (Aidellio)Commented:
so essentially what I've done is replace duplicate "+" with a single "+" and then split the string bases on that delimiter
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Dan CraciunIT ConsultantCommented:
@Rob: you're sure that's php? Cause variables in php should start with $...
0
RobOwner (Aidellio)Commented:
nope not sure at all! it's JavaScript! *smacks head* thanks Dan. I have a saved search that I'd supposed to give me JavaScript questions...
0
RobOwner (Aidellio)Commented:
With PHP the theory still applies:

<?php
$subject = "fred++++nurk+";
$pattern = '/[\+]+/';
$replacement = "+";
$t = preg_replace($pattern, $replacement, $subject);

$terms = preg_split("/\+/", $t);

print_r($terms);

?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dan CraciunIT ConsultantCommented:
Yup. But you forgot the spaces part:
>>get rid of all the spaces and + symbols

$pattern = '/[ +]+/';

Open in new window

0
RobOwner (Aidellio)Commented:
THanks Dan :)
0
Ray PaseurCommented:
If this is a query string (perhaps part of the URL) you might want to look at it with PHP var_dump() to see what is still there after the PHP script receives it.  Just a thought...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.