I have this function works not quite well in PHP 5.2.0, this function cut string into desired length :
function neat_trim($str, $n, $delim='...')
{
$len = strlen($str);
if ($len > $n)
{
preg_match('/(.{' . $n . '}.*?)\b/', $str, $matches);
return rtrim($matches[1]) . $delim;
}
return $str;
}
And I call
$multibyte_string = "Portion of Chicken for 1 person<br>一人份鸡肉";
echo neat_trim($multibyte_string,42) . "</br>";
Will produce
Portion of Chicken for 1 person
一人�...
Unfortunately it won't work on PHP-5.4.29, it will produce:
...