- rtrim: documentation ( source)
- mb_substr: documentation ( source)
- mb_strlen: documentation ( source)
<?php
function shorten($input, $length = 100, $end = '...')
{
if (mb_strlen($input) <= $length) {
return $input;
}
return rtrim(mb_substr($input, 0, $length, 'UTF-8')) . $end;
}
print shorten('The quick brown fox jumped over the lazy dog', 15); // The quick brown...