Custom Length Excerpt


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



Copy this code and paste it in your HTML
  1. function c_excerpt( $string, $max_words, $max_characters ){
  2.  
  3. if(str_word_count($string, 0) > (int)$max_words){
  4. return substr($string, 0, strpos($string, ' ', $max_characters)) . "...";
  5. } else {
  6. return $string;
  7. }
  8.  
  9. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.