Welcome Guest, Not a member yet? Register   Sign In
not correct work of the function character_limiter for not latin symbols
#11

[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);
}


Messages In This Thread
not correct work of the function character_limiter for not latin symbols - by El Forum - 10-10-2008, 03:16 AM



Theme © iAndrew 2016 - Forum software by © MyBB