Remove Redundant Spaces, Tabs and New Lines
Posted: 8 Feb 2013, 4:43am - Friday

It's been a while that I've been dealing with long text. Commonly, users input with redundant new lines, tabs, spaces and long words. Here's my methods and just like others out there; Removing redundant new lines or line breaks:

$str = preg_replace('/(?:(?:\r\n|\r|\n)\s*){2}/s', "\n\n", $str);
Removing redundant tabs:
$str = preg_replace("/[ \t]+/", " ", $str);
Removing redundant spaces:
$str = preg_replace("/[ ]+/", " ", $str);
Shorten long word:
function ellipsis($str, $max = 45) 
{
	if (strlen($str) > $max) 
	{
		$str = '<abbr title="'.strip_tags($str).'">'.substr($str,0,$max).'...</abbr>';
	}
	return $str;
}
I think that's all... Hope this will help you... :)