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?
It's best to abstract you're code like so (notice the limit is optional and defaults to 10):
print limit($string); function limit($var, $limit=10) { if ( strlen($var) > $limit ) { return substr($string, 0, $limit) . '...'; } else { return $var; } }