Word Count: 33
  • Post category:Codings
  • Post last modified:2020-09-23
function trim_words($string, $max_words) {
    $stringArr = explode(' ', $string);
    if(count($stringArr) > $max_words && $max_words > 0) {
    $string = implode(' ', array_slice($stringArr, 0, $max_words)). '...';
    }
    return $string ;
}