@see http://translit-online.ru/yandex.html

@param $string
@return string
195613
static public function slugify($string)
    {
        $slugify = new Slugify([
            'rulesets' => ['default', 'russian'],
            'regexp' => '/([^A-Za-z0-9хХ]|-)+/',
            'lowercase' => true,
            'separator' => "-",
            'trim' => true,
        ]);

        $slugify->addRule('ё', 'yo');
        $slugify->addRule('Ё', 'Yo');

        $slugify->addRule('й', 'j');
        $slugify->addRule('Й', 'J');

        $slugify->addRule('х', 'Х');
        $slugify->addRule('Х', 'Х');

        $slugify->addRule('ц', 'c');
        $slugify->addRule('Ц', 'C');

        $slugify->addRule('щ', 'shch');
        $slugify->addRule('Щ', 'Shch');

        $slugify->addRule('э', 'eh');
        $slugify->addRule('Э', 'Eh');

        //1 step
        $string = $slugify->slugify($string);

        $data = array_map(function ($i) use ($string) {
            return mb_substr($string, $i, 1);
        }, range(0, mb_strlen($string) -1));

        $newData = [];

        if ($data)
        {
            $lastWord = "";
            foreach ($data as $word)
            {
                /**
                 * @see http://translit-online.ru/yandex.html
                 */
                if ($lastWord && in_array($lastWord, ['c', 's', 'e', 'h']) && $word == "х") {
                    $word = "kh";
                } else if ($word == "х") {
                    $word = "h";
                }

                $newData[] = $word;
                if (mb_strlen($word) > 1) {
                    $lastWord = mb_substr($word, mb_strlen($word) - 1, mb_strlen($word));
                } else {
                    $lastWord = $word;
                }

            }
        }

        if ($newData) {
            return implode($newData);
        }

        return $string;
    }
320307
protected function clean($string)
    {
        $string = strip_tags(html_entity_decode($string));
        $string = trim($string);
        $string = $this->translit($string);
        $string = strtolower($string);
        $string = preg_replace($this->getNotAllowedCharsPattern(), '', $string);

        return $string;
    }
1042734
public static function toAscii($string)
    {
        $alnumPattern = '/^[a-zA-Z0-9 ]+$/';

        $string = iconv(
            mb_detect_encoding($string),
            'ASCII//TRANSLIT',
            $string
        );

        $ret = array_map(function ($chr) use ($alnumPattern) {
            if (preg_match($alnumPattern, $chr)) {
                return $chr;
            }
            return '';
        }, str_split($string));

        return implode($ret);
    }
343140
public static function toAscii(string $string): string
    {
        static $transliterator;

        if (!$transliterator && class_exists('Transliterator', false)) {
            $transliterator = \Transliterator::create('Any-Latin; Latin-ASCII');
        }

        $string = preg_replace('~[^\x09\x0A\x0D\x20-\x7E\xA0-\x{2FF}\x{370}-\x{10FFFF}]~u', '', $string);
        $string = strtr($string, '`\'"^~?', "\1\2\3\4\5\6");
        $string = str_replace(
            ["\u{201E}", "\u{201C}", "\u{201D}", "\u{201A}", "\u{2018}", "\u{2019}", "\u{B0}"],
            ["\3", "\3", "\3", "\2", "\2", "\2", "\4"],
            $string
        );

        if ($transliterator) {
            $string = $transliterator->transliterate($string);
        }

        if (ICONV_IMPL === 'glibc') {
            $string = str_replace(
                ["\u{BB}", "\u{AB}", "\u{2026}", "\u{2122}", "\u{A9}", "\u{AE}"],
                ['>>', '<<', '...', 'TM', '(c)', '(R)'],
                $string
            );
            $string = iconv('UTF-8', 'WINDOWS-1250//TRANSLIT//IGNORE', $string);
            $string = strtr(
                $string,
                "\xA5\xA3\xBC\x8C\xA7\x8A\xAA\x8D\x8F\x8E\xAF\xB9\xB3\xBE\x9C\x9A\xBA\x9D\x9F\x9E\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFE\x96\xA0\x8B\x97\x9B\xA6\xAD\xB7",
                'ALLSSSSTZZZallssstzzzRAAAALCCCEEEEIIDDNNOOOOxRUUUUYTsraaaalccceeeeiiddnnooooruuuuyt- <->|-.'
            );
            $string = preg_replace('~[^\x00-\x7F]++~', '', $string);
        } else {
            $string = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $string);
        }

        $string = str_replace(['`', "'", '"', '^', '~', '?'], '', $string);

        return strtr($string, "\1\2\3\4\5\6", '`\'"^~?');
    }
627632
protected function clean($string)
    {
        if ($this->format == 'xml') {
            return $string;
        }

        $string = html_entity_decode($string, ENT_QUOTES, 'UTF-8');
        $string = htmlentities($string, ENT_QUOTES, 'UTF-8');

        if (function_exists('mb_convert_encoding')) {
            $string = mb_convert_encoding($string, 'UTF-8');
        } else {
            $string = utf8_decode($string);
        }

        return $string;
    }
644776
private function to_uri($string)
    {
        static $non_ascii;
        if (!$non_ascii)
        {
            $non_ascii = implode('', range("\x80", "\xFF"));
        }

        $position = 0;
        $strlen = strlen($string);
        while (($position += strcspn($string, $non_ascii, $position)) < $strlen)
        {
            $string = substr_replace($string, sprintf('%%%02X', ord($string[$position])), $position, 1);
            $position += 3;
            $strlen += 2;
        }

        return $string;
    }
728304
protected function _nameConvert($string)
    {
        // if ( !strpos($string, '_') ) {
        //     return strtolower($string);
        // }

        if (strpos($string, 'HTTP_') !== false) {
            $string = substr($string, \strlen('HTTP_'));
        } else {
            return false;
        }

        $arr_char = explode('_', strtolower($string));
        $newString = array_shift($arr_char);

        foreach ($arr_char as $val) {
            $newString .= ucfirst($val);
        }

        return $newString;
    }
641092
protected function normalizeString($string)
    {
        if (false === strpos($string, '_')) {
            return $string;
        }

        return preg_replace_callback('/_([a-zA-Z0-9])/', function ($matches) {
            return strtoupper($matches[1]);
        }, $string);
    }
1373331
protected function translit($string)
    {
        $stringOutput = (@iconv('UTF-8', 'ASCII//TRANSLIT', $string));
        if ($stringOutput === false) {
            $string = preg_replace('!([^0-9a-zA-Z\.,:;()/-_\s])!', '', $string); // use more explicit statement, alphanum dont do the job
            $stringOutput = (@iconv('UTF-8', 'ISO-8859-1//TRANSLIT', $string));
            if ($stringOutput === false) {
                throw new \Exception('Cant convert '.$string);
            }
        }

        return $stringOutput;
    }
535237
public static function strToLower($string)
    {
        $string = str_replace(self::$upperTR, self::$lowerTR, $string);

        return mb_strtolower($string, 'UTF-8');
    }
869344
public static function generatealias($string){
		$str=self::translit($string);
		//echo('translit ('.$string.')='.$str.'<br>');
		$str=mb_strtolower($str,'UTF-8');
		//echo('alias ('.$string.')='.$str.'<br>');
		$str=str_replace('\'', '', $str);
		//echo('alias ('.$string.')='.$str.'<br>');
		$str=preg_replace('~[^-a-z0-9_]+~u', '-', $str);
		//echo('alias ('.$string.')='.$str.'<br>');
		$str=trim($str, "-");
		//echo('alias ('.$string.')='.$str.'<br>');
		return $str;
		}
496796
private function stringToUsernameChunk($string)
    {
        $string = trim((string) $string);
        $string = preg_replace('/[^a-z0-9]+/', '_', strtolower($string));
        $string = preg_replace('/__+/', '_', $string);
        $string = trim($string, '_');

        return $string;
    }
534307
public function apply(string $string) : string
    {
        return preg_replace($this->pattern, $this->replacement, $string);
    }
176664
protected function convertKeywords($string)
    {
        $string = str_replace('\Closure', 'Closure', $string);
        $string = str_replace('Closure', '\Closure', $string);
        $string = str_replace('dynamic', 'mixed', $string);

        return $string;
    }
236724
public function html($string)
    {
        if (!$string) {
            return $string;
        }

        $result = htmlspecialchars($string, $this->htmlSpecialCharsFlags, $this->encoding);
        return $result;
    }
719838
final public static function handlifyString($string)
    {
        $string = preg_replace('/\W+/', '_', $string);
        $string = preg_replace('/([A-Z])/', '_$1', $string);
        $string = strtolower($string);
        $string = preg_replace('/_+/', '_', trim($string, '_'));

        return $string;
    }
1071099
private function normalize(string $string): string
    {
        return \str_replace($this->normalizeFrom, $this->normalizeTo, $string);
    }