24
May I make a modification to pallan's code?
$truncated = (strlen($string) > 20) ? substr($string, 0, 20) . '...' : $string;
This doesn't add the '...' if it is shorter.
echo substr($str,0,25)."...";
Would do the trick, but if you are dealing with words, you might want to cut off on word boundries so you don't have partial word doig this: The quick bl...
So to do that (crude off the top of my head):
$words = split(" ", strlen($str));
for($i = 0,$j=0; $i< 25 && $j < sizeof($words) ;$j++)
{
$i += strlen($words[$j]);
echo $words[$j]. " ";
}
echo "...";