Skip to content

Instantly share code, notes, and snippets.

@yeco
Created September 25, 2012 15:42
Show Gist options
  • Select an option

  • Save yeco/3782666 to your computer and use it in GitHub Desktop.

Select an option

Save yeco/3782666 to your computer and use it in GitHub Desktop.
truncate.php
function truncate($text,$numb) {
$text = html_entity_decode($text, ENT_QUOTES);
if (strlen($text) > $numb) {
$text = substr($text, 0, $numb);
$text = substr($text,0,strrpos($text," "));
$etc = " ...";
$text = $text.$etc;
}
$text = htmlentities($text, ENT_QUOTES);
return $text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment