Try this bit of code:
(I'm not sure about the 3rd line, the \s might be picked up by the PHP parser. If it complains, change \s to \\s.)
// \s can be any whitespace character (\n, \t, " "), the + means once or more.
// Whenever any whitespace is found in the entire string, it's removed...