Stripping Whitespace Characters from a String
How can you strip all whitespace characters from a string in PHP?
Problem
The php_strip_whitespace() function and the preg_replace() function with a whitespace character are not working.
Answer
To strip any whitespace character, use a regular expression:
$str = preg_replace('/\s+/', '', $str);
Note that this regular expression also handles whitespace in UTF-8 strings.
The above is the detailed content of How to Strip Whitespace Characters from a String in PHP?. For more information, please follow other related articles on the PHP Chinese website!