1function limit_text($text, $limit) {
2 if (str_word_count($text, 0) > $limit) {
3 $words = str_word_count($text, 2);
4 $pos = array_keys($words);
5 $text = substr($text, 0, $pos[$limit]) . '...';
6 }
7 return $text;
8}
9
10echo limit_text('Hello here is a long sentence that will be truncated by the', 5);