Hi andrius,
Ahhh . . . the problem is that teh code is using substr() with UTF characters and it doesn't correctly find the character breaks.
If you have multi-byte string mbstring PHP extension installed then mb_substr would presumably work.
If not, then in the PHP Manual Notes for substr() there are a couple of alternatives suggested - functions that only break on spaces; and functions that try to recognise UTF characters correctly and only break on character boundaries.
Adding one of these would probably fix the problem.
// function to break on spaces
function str_stop($string, $max_length)
{
if ( strlen($string) > $max_length ){
$string = substr($string, 0, $max_length);
$pos = strrpos($string, " ");
if($pos === false) {
return substr($string, 0, $max_length)."...";
}
return substr($string, 0, $pos)."...";
} else {
return $string;
}
}
<?php
function utf8_substr($string, $start)
{
preg_match_all("/./su", $string, $ar);
if ( func_num_args() >= 3 ) {
$end = func_get_arg(2);
return join("", array_slice($ar[0], $start, $end));
} else {
return join("", array_slice($ar[0], $start));
}
}
?>
Neither of these are tested here - I think I've used the first function successfully before.
Bob