Last active
November 6, 2015 16:50
-
-
Save pixelbart/acaa1ba8ad8d000b9f8f to your computer and use it in GitHub Desktop.
Text shortener
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
<?php | |
/** | |
* Text Shortener | |
*/ | |
function shortText($string, $lenght) | |
{ | |
if(strlen($string) > $lenght) { | |
$string = substr($string, 0, $lenght)."..."; | |
$string_end = strrchr($string, " "); | |
$string = str_replace($string_end, " ...", $string); | |
} | |
return $string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment