word limit in php

Solutions on MaxInterview for word limit in php by the best coders in the world

showing results for - "word limit in php"
Domenico
29 Mar 2020
1echo str_word_count("word count function");
2
Isaac
17 Jun 2016
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);