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.

Posted By: makedon on May 9, 2009

// makeTeaser: makes a teaser for the number of words specified function makeTeaser($text, $numWords) { $words = split(' ', $text); $words = arraychunk($words, $numWords); $output = implode(' ', $words[0]); $output = striptags($output) . '...';

return $output; }

You need to login to post a comment.