Categories > TBS free chat >

解决中文截取出现乱码的问&#39...

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: chenguojun
Date: 2007-12-29
Time: 04:25

解决中文截取出现乱码的问题

            case 3: if (strlen(''.$CurrVal)>$Loc->OpePrm[$i]) $CurrVal = substr(''.$CurrVal,0,$Loc->OpePrm[$i]).$Loc->OpeEnd; break;
chage
            case 3: if (strlen(''.$CurrVal)>$Loc->OpePrm[$i]) $CurrVal = len_substr(''.$CurrVal,0,$Loc->OpePrm[$i]).$Loc->OpeEnd; break;


//len_substr

    function len_substr($string, $from, $length = null)
    {
    $match = '';
    $result = '';
        preg_match_all('/[\x80-\xff]?./', $string, $match);
        if(is_null($length)){
            $result = implode('', array_slice($match[0], $from));
        }else{
            $result = implode('', array_slice($match[0], $from, $length));
        }
        return $result;
    }