Many times its required that we truncate a long string and add ellipsis to the end of the truncated string. Here's a function which does exactly that.
Code: PHP
function truncate( $varb, $num )
{
$dnum = intval($num);
if (strlen($varb)>$dnum)
{
$nvarb = substr($varb, 0, $dnum);
$nvarb .= " ...";
}
else if (strlen($varb)<$dnum)
{
$nvarb=$varb;
}
return $nvarb;
}