Excerpt with Tag Stripping


/ Published in: PHP
Save to your folder(s)

Create an excerpt from the main copy, removing any image or other HTML tag markup so it will be clean. In this case the length is 160 characters, change that number to change the length of the excerpt


Copy this code and paste it in your HTML
  1. public function makeNewsExcerpt($content)
  2. {
  3. $content = preg_replace("(\<(/?[^\>]+)\>)", "", $content);
  4. $content = substr($content, 0, 160);
  5. $content .= "...";
  6. return $content;
  7.  
  8. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.