How to remove space between words?

G’day to all.

I am familiar with some of the php in-built functions to trim(), strip_tags etc, but one I haven’t come across yet is to be able to remove a space between words (a single space that is.)

E.g. I want to be able to use a php function that makes:
This text

change to:
Thistext

How do I achieve this?

Explode and Implode maybe?

Or str_replace()


$word = "This is my text";
$word = str_replace( ' ', '', $word );  

Im sure if you check in the php manual there are string functions. A quick look through that would have showed you how to do it :stuck_out_tongue:

Fantastic! Thanks cascadingStylez - str_replace did it. Thanks


$str = "This text";
$str = preg_replace('/\\s/','',$str);
echo $str;

That would be a good method to use if you want to remove other characters, such a punctuation, from a string aswell.

You would need to construct a regular expression mind you. Not difficult at all if you understand regular expressions.