In this example you will learn, how to Strip All Spaces Out of a String in PHP. You can simply use the PHP str_replace() function to strip or remove all spaces inside a string.
Let’s take a look at the following example to see how it actually works:
$str = 'This is a simple piece of text.';
$new_str = str_replace(' ', '', $str);
echo $new_str; // Outputs: Thisisasimplepieceoftext.
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.