Skip to content

Instantly share code, notes, and snippets.

@amgraham
Created October 12, 2010 04:48
Show Gist options
  • Save amgraham/621673 to your computer and use it in GitHub Desktop.
Save amgraham/621673 to your computer and use it in GitHub Desktop.
Return only the beginning and end of a long string
function snipper($string, $length) {
// snipper('SuperLongStringThatMightNotFitInTheSpaceAllowed', 10)
// will return
// SuperLongS...aceAllowed
if (strlen($string) > $length) {
$string = substr($string, 0, $length). "...".substr($string, strlen($string) - $length, $length);
}
return $string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment