daily pastebin goal
68%
SHARE
TWEET

Untitled

a guest Mar 23rd, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * This function truncates a string to the desired character limit
  3.  * without cutting words.
  4.  *
  5.  * Adds ellipsis at the end
  6.  *
  7.  * @param  string $str        The string to be truncated
  8.  * @param  int    $limit      Number of characters to display
  9.  * @return string $str        Return the truncated string
  10.  */
  11. function strcut( $str = '', $limit = 250 ) {
  12.  
  13.     if( strlen( $str ) > $limit ) :
  14.  
  15.         $str = substr( $str, 0, $limit);    
  16.         $str = substr( $str, 0, strrpos( $str, ' ' )) . '...';
  17.         $str = strip_tags( $str );
  18.  
  19.     endif;
  20.  
  21.     $str = str_replace( "\n", ' ', $str );
  22.  
  23.     return $str;
  24.  
  25. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top