PHPRO.ORG

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);
}