Jump to content

Quick PHP question :)


Cronthenoob

Recommended Posts

How do I remove spaces from something a user typed in?If they type "hello world" into the text box and hit submit, how would i make it submit as "helloworld"??php.net doesnt like me and I can't really find anything on that site ever. I've used this before but can't remember what it is.

Link to comment
Share on other sites

To turn multiple spaces into one space, you'll need a regular expression like this:

$RegExp = '%[\s]{2,}%';$Text = preg_replace($RegExp, ' ', $Unfiltered);

Hope it helps :)EDIT: Oh, i missunderstood what you wanted to do. Instead of using a regular expression, this should work just as well:

$Text = str_replace(' ', '', $Text)

That will give you what you need, and it's plenty faster than regular expressions too.

Link to comment
Share on other sites

To turn multiple spaces into one space, you'll need a regular expression like this:
$RegExp = '%[\s]{2,}%';$Text = preg_replace($RegExp, ' ', $Unfiltered);

Hope it helps :)EDIT: Oh, i missunderstood what you wanted to do. Instead of using a regular expression, this should work just as well:

$Text = str_replace(' ', '', $Text)

That will give you what you need, and it's plenty faster than regular expressions too.

Thanks! That works. :)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...