<?php
$string = "the quick brown fox jumps over the lazy dog";
for($limit = 10; $limit <= strlen($string); $limit += 10) {
    print_r(display_short($string, $limit));
}

function display_short($str, $limit, $ellipsis = '...') {
    if (strlen($str) <= $limit) {
        return $str;
    }

    $limit -= strlen($ellipsis);
    $pos = strrpos($str, ' ', $limit - strlen($str));
    if ($pos === false) {
        $pos = $limit;
    }
    
    return substr($str, 0, $pos).$ellipsis;
}
