Return to Snippet

Revision: 18837
at October 9, 2009 16:48 by jspicher


Initial Code
function truncateText($string, $limit, $break=" ", $pad="..."){
	if(strlen($string) <= $limit) return $string;
	$string = substr($string, 0, $limit);
	if(false !== ($breakpoint = strrpos($string, $break))) {
	$string = substr($string, 0, $breakpoint);}
	return $string . $pad;}

Initial URL

                                

Initial Description
Used to cleanly truncate text.

Initial Title
truncateText($string, $limit, $break=" ", $pad="...")

Initial Tags
php, text, function

Initial Language
PHP