I have the following function that replaces strings with more than 32 characters with "...". My problem is that if an umlaut falls in the range of 29th - 33rd character, it is represented by a weird character. How do I alter the function to show the entire umlaut without breaking it, despite what number length I place in the variable $length?
For example, there are 31 characters ahead of für, but using the function below, it gives 31 characters plus f�...
function textLimit($string, $length, $replacer = '...')
{
if(strlen($string) > $length)
return (preg_match('/^(.*)\W.*$/', substr($string, 0, $length+1), $matches) ? $matches[1] : substr($string, 0, $length)) . $replacer;
return $string;
}