DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Make An HTML Correct Teaser

07.05.2011
| 3474 views |
  • submit to reddit
        
// makeTeaser: makes a teaser for the number of words specified
function makeTeaser($text, $numWords) {
  $words = split(' ', $text);
  $words = array_chunk($words, $numWords);
  $output = implode(' ', $words[0]);
  $output = strip_tags($output) . '...';
  
  return $output;
}