Remove excess whitespace from within a string
Not sure exactly what you want but here are two situations:
If you are just dealing with excess whitespace on the beginning or end of the string you can use
trim()
,ltrim()
orrtrim()
to remove it.If you are dealing with extra spaces within a string consider a
preg_replace
of multiple whitespaces" "*
with a single whitespace" "
.
Example:
$foo = preg_replace('/\s+/', ' ', $foo);
$str = str_replace(' ','',$str);
Or, replace with underscore, & nbsp; etc etc.