0

I have a form which currently accepts a tabbled white space " " for example. I only want to allow one space between words.

Currently it looks like this:

preg_replace ("#[^0-9a-z]#i", " ",$string);

Remember I need to allow only one space at a time, How do I fix this?

1 Answer 1

1

Replace multiple whitespaces with a single space

$string = preg_replace('/\s\s+/',' ', $string);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.