[eluser]emperius[/eluser]
I've checked mb-string is set up on the hosting and is working for usual stings but for the stings taken from database the number of symbols is returned wrong
here is the code of the character_limiter function
Code:
function character_limiter($str, $n = 500, $end_char = '…')
{
if (mb_strlen($str) < $n)
{
return $str;
}
//$str = preg_replace("/\s+/", ' ', preg_replace("/(\r\n|\r|\n)/u", " ", $str));
$str = preg_replace("/S+\s+/", ' ', preg_replace("/(\r\n|\r|\n)/", ' ', $str));
if (mb_strlen($str) <= $n)
{
return $str;
}
$out = "";
foreach (explode(' ', trim($str)) as $val)
{
$out .= $val.' ';
if (mb_strlen($out) >= $n)
{
return trim($out).$end_char;
}
}
}
and here is the example of my code
Code:
$query = mysql_query("SELECT Name FROM Table");
if(mysql_num_rows($query)>0)
{
$arr = mysql_fetch_array($query);
echo character_limiter($arr['Name'], 10);
}