Collapse Whitespace
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.
<?php
/**
*
* @Collapse all spaces to a single space
*
* @param string $string
*
* @return string
*
*/
function collapseWhiteSpace($string){
return preg_replace('/\s+/', ' ', $string);
}
Support PHPRO.ORG
Search
PHPRO.ORG Poll
Warning: Participation in PHPRO.ORG polls may incorrectly lead you to believe your opinions matter.

RSS Feed




