Skip to content

Instantly share code, notes, and snippets.

@KnightAlex
Created March 1, 2013 15:24
Show Gist options
  • Save KnightAlex/5065357 to your computer and use it in GitHub Desktop.
Save KnightAlex/5065357 to your computer and use it in GitHub Desktop.
PHP function to shorten a string
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