11
strtruncate
strtruncate
SYNOPSIS
strtruncate($s, $len, $atword=false)
DESCRIPTION
strtruncate
returns the string $s
cut to $len
characters, at the end of a word if $atword
is true
, followed by three dots (ELLYPSIS).
CODE
- function strtruncate($s, $len, $hellip='...', $atword=false) {
- return strlen($s) > $len ? ($atword ? preg_replace("/^(.{1,$len})(\s.*|$)/s", '\\1' . $hellip, $s) : substr($s, 0, $len) . $hellip) : $s;
- }
Comments