Вход Регистрация
Файл: adultscript-2.0.3-pro/files/libraries/framework/multibyte.php
Строк: 164
<?php
defined
('_VALID') or die('Restricted Access!');

if (!
preg_match('/^.$/u''ñ')) {
     die(
'<a href="http://php.net/pcre">PCRE</a> has not been compiled with UTF-8 support. '.
        
'See <a href="http://php.net/manual/reference.pcre.pattern.modifiers.php">PCRE Pattern Modifiers</a> '.
        
'for more information. This application cannot be run without UTF-8 support.');
}

if (
function_exists('mb_strlen')) {
    
define('MBSTRING'TRUE);
    if (
version_compare(PHP_VERSION'5.6''<')) {
        
ini_set('mbstring.internal_encoding''UTF-8');
          
ini_set('mbstring.http_input''UTF-8');
          
ini_set('mbstring.http_output''UTF-8');
      }
} else {
    
define('MBSTRING'FALSE);
}

function 
utf8_is_ascii($str)
{
    return !
preg_match('/[^x00-x7F]/S'$str);
}

function 
utf8_strlen($str)
{
    if (
MBSTRING) {
        return 
mb_strlen($str);
    }
    
    return (
utf8_is_ascii($str)) ? strlen($str) : strlen(utf8_decode($str));
}

function 
utf8_clean($str)
{
    if (
is_array($str)) {
        foreach (
$str as $key => $value) {
            
$str[utf8_strip_ascii_ctrl($key)] = utf8_strip_ascii_ctrl($value);
        }
    } elseif (
is_string($str) && $str != '') {
        
$str utf8_strip_ascii_ctrl($str);
    }
    
    return 
$str;
}

function 
utf8_strip_ascii_ctrl($str)
{
    return 
preg_replace('/[x00-x08x0Bx0Cx0E-x1Fx7F]+/S'''$str);
}

function 
utf8_strip_non_ascii($str)
{
    return 
preg_replace('/[^x00-x7F]+/S'''$str);
}

function 
utf8_replace_accents($str$case=0)
{
    if (!
utf8_is_ascii($str)) {
        
VF::load('framework.multibyte.utils.accents');
        return 
_transliterate_accents($str$case);
    }
    
    return 
$str;
}

function 
utf8_strpos($str$needle$offset NULL)
{
    if (
MBSTRING) {
        return (
is_null($offset)) ? mb_strpos($str$needle) : mb_strpos($str$needle$offset);
    }

    if (
utf8_is_ascii($str)) {
        return (
is_null($offset)) ? strpos($str$needle) : strpos($str$needle$offset);
    }

    
VF::load('framework.multibyte.strpos');
    if (
is_null($offset)) {
        return 
_utf8_strpos($str$needle);
    } else {
        return 
_utf8_strpos($str$needle$offset);
    }
}

function 
utf8_substr($str$offset$length NULL)
{
    if (
MBSTRING) {
        return (
is_null($length)) ? mb_substr($str$offset) : mb_substr($str$offset$length);
    }

    if (
utf8_is_ascii($str)) {
        return (
is_null($length)) ? substr($str$offset) : substr($str$offset$length);
    }

    
VF::load('framework.multibyte.substr');
    if (
is_null($str)) {
        return 
_utf8_substr($str$offset);
    } else {
        return 
_utf8_substr($str$offset$length);
    }
}

function 
utf8_trim($str$charlist FALSE)
{
    if (
$charlist === FALSE) {
        return 
trim($str);
    }

    if (
utf8_is_ascii($str)) {
        return 
trim($str);
    }
    
    
VF::load('framework.multibyte.ltrim');
    
VF::load('framework.multibyte.rtrim');
    return 
_utf8_ltrim(_utf8_rtrim($str$charlist), $charlist);
}

function 
utf8_ltrim($str$charlist FALSE)
{
    if (
$charlist === FALSE) {
        return 
ltrim($str);
    }

    if (
utf8_is_ascii($charlist)) {
        return 
ltrim($str);
    }

    
VF::load('framework.multibyte.ltrim');
    return 
_utf8_ltrim($str$charlist);
}

function 
utf8_rtrim($str$charlist FALSE)
{
    if (
$charlist === FALSE) {
        return 
rtrim($str);
    }

    if (
utf8_is_ascii($charlist)) {
        return 
rtrim($str);
    }

    
VF::load('framework.multibyte.rtrim');
    return 
_utf8_rtrim($str$charlist);
}

function 
utf8_strtolower($string)
{
    if (
MBSTRING) {
        return 
mb_strtolower($string);
    }

    if (
utf8_is_ascii($string)) {
        return 
strtolower($string);
    }

    
VF::load('framework.multibyte.utils.unicode');
    
VF::load('framework.multibyte.strtolower');
    return 
_utf8_strtolower($string);
}

function 
utf8_strtoupper($string)
{
    if (
MBSTRING) {
        return 
mb_strtoupper($string);
    }
    
    if (
utf8_is_ascii($string)) {
        return 
strtoupper($string);
    }

    
VF::load('framework.multibyte.utils.unicode');
    
VF::load('framework.multibyte.strtoupper');
    return 
_utf8_strtoupper($string);
}

function 
utf8_ucfirst($string)
{
    if (
MBSTRING) {
          
$fc mb_strtoupper(mb_substr($string01));
          return 
$fc.mb_substr($string1);    
    }
    
    if (
utf8_is_ascii($string)) {
        return 
ucfirst($string);
    }
    
    
VF::load('framework.multibyte.ucfirst');
    
    return 
_utf8_ucfirst($string);
}

function 
utf8_wordwrap($string$width=75$break="n"$cut=FALSE)
{
    if (
utf8_is_ascii($string)) {
        return 
wordwrap($string$width$break$cut);
    }
    
    
$string preg_split('#[snr]+#'$string);
    
$length 0;
    foreach (
$string as $val) {
          
$val     .= ' ';
        
$tmp      utf8_strlen($val);
        
$length += $tmp;
        if (
$length >= $width) {
              
$return .= $break $val;
            
$length  $tmp;
        } else {
            
$return .= $val;
        }
    }
        
    return 
$return;
}
?>
Онлайн: 0
Реклама