Tutorial Options to Truncate Strings
Technique #1: Simple function myTruncate($string, $limit, $break=".", $pad="...") { if(strlen($string) i...
https://iskablogs.blogspot.com/2014/03/tutorial-options-to-truncate-strings.html
Technique #1: Simple
function myTruncate($string, $limit, $break=".", $pad="...") {
if(strlen($string) <= $limit) return $string;
if(false !== ($breakpoint = strpos($string, $break, $limit))) {
if($breakpoint < strlen($string) - 1) {
$string = substr($string, 0, $breakpoint) . $pad; }
} return $string;
}
Technique #2: Simple
function myTruncate($string, $limit, $break=".", $pad="...") {
if(strlen($string) <= $limit) return $string;
if(false !== ($breakpoint = strpos($string, $break, $limit))) {
if($breakpoint < strlen($string) - 1) {
$string = substr($string, 0, $breakpoint) . $pad; }
} return $string;
}
Technique #2: Simple