Tagged: Truncate String by Words

Truncate String by Words using PHP ?

Technique #1 <?php function trunc($phrase, $max_words) { $phrase_array = explode(‘ ‘,$phrase); if(count($phrase_array) > $max_words && $max_words > 0) $phrase = implode(‘ ‘,array_slice($phrase_array, 0, $max_words)).’…’; return $phrase; } ?> Technique #2 function limit_words($words, $limit, $append...