How can I get the first n characters of a string in PHP? What\'s the fastest way to trim a string to a specific number of characters, and append \'...\' if needed?
The function I used:
function cutAfter($string, $len = 30, $append = '...') { return (strlen($string) > $len) ? substr($string, 0, $len - strlen($append)) . $append : $string; }
See it in action.