Created
July 26, 2015 22:17
-
-
Save jordanneenan/55fa3a4ba1361f389ef6 to your computer and use it in GitHub Desktop.
Truncate a string...nicely.
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
//truncate a string...nicely | |
function stringTruncate($string, $stringLength){ | |
if (strlen($string) > $stringLength) { | |
$string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $stringLength)); | |
return $string . '...'; | |
}else{ | |
return $string; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment