Codice PHP:
function myfragment($str, $n, $delim='...')
{
if (strlen($str) > $n) {
preg_match('/(.{' . $n . '}.*?)\b/', $str, $matches);
return rtrim($matches[1]) . $delim;
}
else
return $str;
}
Codice PHP:
function myfragment($str, $n, $delim='...')
{
if (strlen($str) > $n) {
preg_match('/(.{' . $n . '}.*?)\b/', $str, $matches);
return rtrim($matches[1]) . $delim;
}
else
return $str;
}