SyntaxFix
Write A Post
Hire A Developer
Questions
str_replace will do the trick thusly
$new_str = str_replace(' ', '', $old_str);