Rate this script:  I Love it  /   I Hate it

Truncate String by Words


Code


<?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;
}
?>
 

 

 
Truncate String by Words scripts | Truncate String by Words snippet | Truncate String by Words example | Truncate String by Words tutorial | Truncate String by Words code