Shorten string with a "..." body
if (strlen($string) >= 20) {
echo substr($string, 0, 10). " ... " . substr($string, -5);
}
else {
echo $string;
}
The third argument of substr()
is a length, not an end. Just pass 5
instead.
Also, substr($string, -5)
.