Pages

Friday, January 11, 2013

php limit text by word


function limit_text($text, $limit)
{
  $words = str_word_count($text, 2);
  if ( count($words) > $limit)
  {
 $pos = array_keys($words);
 $text = substr($text, 0, $pos[$limit]) . '...';
  }
 return $text;
}

No comments:

Post a Comment