Monday, 2 February 2015

Collapse Whitespace

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

0 comments:

Post a Comment