Tutorial Truncate String by Words
Technique #1 function trunc($phrase, $max_words) { $phrase_array = explode(' ',$phrase); if(count($phrase_array) > $max_wor...
https://iskablogs.blogspot.com/2014/03/tutorial-truncate-string-by-words.html
Technique #1
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 = ' …') {
// Add 1 to the specified limit becuase arrays
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 = ' …') {
// Add 1 to the specified limit becuase arrays