Вход Регистрация
Файл: adultscript-2.0.3-pro/files/libraries/framework/text.php
Строк: 70
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VText
{
    public static function 
truncate_chars($text$limit=100$replace=' ...'$preserve_words=FALSE)
    {
        
$limit  = (int) $limit;
        
$length utf8_strlen($text);
        if (
$length $limit) {
            return 
$text;
        }
        
        if (
$preserve_words === FALSE)
            return 
utf8_substr($text0$limit).$replace;
        
        if (!
preg_match('/^.{0,'.$limit.'}s/us'$text$matches))
            return 
NULL;

        return 
rtrim($matches[0]).(strlen($matches[0]) === strlen($text) ? '' $replace);
    }
    
    public static function 
truncate_words($text$limit=100$replace='...')
    {
        
$limit     = (int) $limit;
        
$length utf8_strlen($text);
        if (
$length $limit) {
            return 
$text;
        }
        
        
preg_match('/^s*+(?:S++s*+){1,'.$limit.'}/u'$text$matches);
        
        return 
utf8_rtrim($matches['0']).(utf8_strlen($matches['0']) === $length '' $replace);
    }
    
    public static function 
random($type='alnum'$length=8)
    {
        
$random '';
        
$alnum  'abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ';
        switch (
$type) {
            case 
'alnum':
                
$chars $alnum;
                break;
            case 
'alpha':
                
$chars 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
                break;
            case 
'numeric':
                
$chars '0123456789';
                break;
            case 
'password':
                
$chars 'abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ`~!@#$%^&*()_-+={}[]|;":,<>/?';
                break;
            default:
                
$chars $alnum;
        }
        
        
$i 1;
        
$m strlen($chars)-1;
        while (
$i <= (int) $length) {
            
$rand    rand(1$m);
            
$random .= $chars[$rand];
            ++
$i;
        }
        
        return 
$random;
    }
    
    public static function 
cycle()
    {
        static 
$i;
        
        if (
func_num_args() === 0) {
            
$i 0;
            return 
'';
        }

        
$args func_get_args();
        return 
$args[($i++ % count($args))];
    }
    
    public static function 
bytes($bytes)
    {
        
$bytes    = (int) $bytes;
        if (
$bytes === 0) {
            return 
0;
        }
    
        
$i         0;
        
$formats = array('B','KB','MB','GB','TB','PB');
        while (
$bytes >= 1024) {
            
$bytes $bytes 1024;
            ++
$i;
        }
        
        return 
number_format($bytes,($i 0), ',''.').' '.$formats[$i];
    }
    
    public static function 
dos2unix($text)
    {
        return 
preg_replace('/(rn|r|n)/s'"n"$text);
    }
}
?>
Онлайн: 0
Реклама