×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Mark Foster
Added: Sep 1, 2013 10:42 AM
Views: 13
Tags: no tags
  1. <?php
  2. function trunc($phrase, $max_words) {
  3.    $phrase_array = explode(' ',$phrase);
  4.    if(count($phrase_array) > $max_words && $max_words > 0)
  5.       $phrase = implode(' ',array_slice($phrase_array, 0, $max_words)).'...';
  6.    return $phrase;
  7. }
  8. ?>