Created
March 1, 2013 15:24
-
-
Save KnightAlex/5065357 to your computer and use it in GitHub Desktop.
PHP function to shorten a string
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
function shortenText($text, $chars) { | |
// Change to the number of characters you want to display | |
$text = $text." "; | |
$text = substr($text,0,$chars); | |
$text = substr($text,0,strrpos($text,' ')); | |
$text = $text."..."; | |
return $text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment