To count words in a php string usually we can use str_word_count but I think not always a good solution
$var =\"Hello world!\"; echo str_
ans:
function limit_text($text, $limit) { if(str_word_count($text, 0) > $limit) { $words = str_word_count($text, 2); $pos = array_keys($words); $text = substr($text, 0, $pos[$limit]) . '...'; } return $text; }