Skip to content

Instantly share code, notes, and snippets.

@QuestionDevelopment
Created August 23, 2013 20:04
Show Gist options
  • Save QuestionDevelopment/6323434 to your computer and use it in GitHub Desktop.
Save QuestionDevelopment/6323434 to your computer and use it in GitHub Desktop.
function truncateString($str, $max, $rep = '...') {
if(strlen($str) > $max) {
$leave = $max - strlen($rep);
return substr_replace($str, $rep, $leave);
} else {
return $str;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment