If you have file or string from who-knows-where and it is double-spaced, or just has large blocks of whitespace, this little function will collapse it all to a single space.
* @Collapse all spaces to a single space
* @param string $string
* @return string
return preg_replace('/\s+/', ' ', $string);