Truncate String by Words
1 2 <?php 3 4 function trunc($phrase, $max_words) 5 { 6 $phrase_array = explode(' ',$phrase); 7 if(count($phrase_array) > $max_words && $max_words > 0) 8 $phrase = implode(' ',array_slice($phrase_array, 0, $max_words)).'...' 9 return $phrase; 10 } 11 ?>