Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This function truncates a string to the desired character limit
- * without cutting words.
- *
- * Adds ellipsis at the end
- *
- * @param string $str The string to be truncated
- * @param int $limit Number of characters to display
- * @return string $str Return the truncated string
- */
- function strcut( $str = '', $limit = 250 ) {
- if( strlen( $str ) > $limit ) :
- $str = substr( $str, 0, $limit);
- $str = substr( $str, 0, strrpos( $str, ' ' )) . '...';
- $str = strip_tags( $str );
- endif;
- $str = str_replace( "\n", ' ', $str );
- return $str;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement