Possible duplicate:
Trim a multibyte string by n characters
Hello,
I am developing a site in French and I created a function that cuts the string after X number of characters. It works great, but when the last character has an accent, he has a symbol (?), Not a symbol.
Here is my function
function neat_trim3($str, $n, $delim='...') {
$len = strlen($str);
if ($len > $n) {
$tocut = $len-$n;
$output = substr($str,0,-$tocut);
return $len.' - '.$output.$delim;
}
else {
return $str;
}
}
Example
$str = "C'est une soirée privé ce soir";
echo eat_trim3($str, 15 , '...' );
The rest of the page fine-tunes the page, I can even repeat the same line without a cut, and it works fine.
Any help was appreciated.
Thank.
source
share