Skip to content

Instantly share code, notes, and snippets.

@psics
Created August 2, 2017 17:29
Show Gist options
  • Save psics/0d362b736391ba5518d73a5ebbb5cd4f to your computer and use it in GitHub Desktop.
Save psics/0d362b736391ba5518d73a5ebbb5cd4f to your computer and use it in GitHub Desktop.
//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