Created
August 2, 2017 17:29
-
-
Save psics/0d362b736391ba5518d73a5ebbb5cd4f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//truncate text | |
function truncate_text($string, $lenght) { | |
if( strlen( $string ) >= $lenght ) { | |
$string = strip_tags($string); | |
$string = substr($string, 0, $lenght); | |
$string = rtrim($string, "!,.-"); | |
$string = substr($string, 0, strrpos($string, ' ')); | |
$string = $string."… "; | |
} | |
return $string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment