We Recommend

HTML: The Definitive Guide HTML: The Definitive Guide
They teach you that learning HTML is like learning any other language and that reading a book of rules can only take you so far. Readers begin writing what may be their first Web page just two pages into the book's second chapter. From there on, they provide a wide range of HTML coding to allow readers to learn from good examples. The book includes a handy "cheat sheet" of HTML codes for quick reference.


Posted By

JuliaKM on 09/21/07


Tagged

textmate drupal teaser


Versions (?)


Who likes this?

3 people have marked this snippet as a favorite

basicmagic
kellyharding
heinz1959


Make an HTML Correct Teaser


Published in: HTML 


  1. // makeTeaser: makes a teaser for the number of words specified
  2. function makeTeaser($text, $numWords) {
  3. $words = split(' ', $text);
  4. $words = array_chunk($words, $numWords);
  5. $output = implode(' ', $words[0]);
  6. $output = strip_tags($output) . '...';
  7.  
  8. return $output;
  9. }
  10.  

Report this snippet 

Comments

RSS Icon Subscribe to comments
Posted By: berkes on September 21, 2007

How does this correct the HTML? AFAIKS it does a far worse job then core. Core teaser splitter at least tries to take HTML tags into consideration.

Posted By: JuliaKM on November 9, 2007

You're totally right. I posted this after messing around with a teaser from another CMS.

You need to login to post a comment.