Transliterate a string from an alphabet into another alphabet.

@param string $str       The string to be converted.
@param System $system    (Optional) Override default transliteration system.

@return string Converted string.
978245
public function transliterate($str, $system = null) {
        if(is_null($system)) {
            $system = $this->system;
        }
        if(is_null($system)) {
            throw new RuntimeException("Transliteration system is not defined");
        }
        return $system->transliterate($str);
    }
951407
public static function unicode_to_utf8( &$str )
    {
        if (!is_array($str)) return '';

        $utf8 = '';
        foreach( $str as $unicode ) {
            if ( $unicode < 128 ) {
                $utf8.= chr( $unicode );
            } elseif ( $unicode < 2048 ) {
                $utf8.= chr( 192 +  ( ( $unicode - ( $unicode % 64 ) ) / 64 ) );
                $utf8.= chr( 128 + ( $unicode % 64 ) );
            } else {
                $utf8.= chr( 224 + ( ( $unicode - ( $unicode % 4096 ) ) / 4096 ) );
                $utf8.= chr( 128 + ( ( ( $unicode % 4096 ) - ( $unicode % 64 ) ) / 64 ) );
                $utf8.= chr( 128 + ( $unicode % 64 ) );
            }
        }
        return $utf8;
    }
288744
protected static function convertToLowercase($str)
    {
        $explodedStr = explode('_', $str);

        if (count($explodedStr) > 1) {
            $lowerCasedStr = [];
            foreach ($explodedStr as $value) {
                $lowerCasedStr[] = strtolower($value);
            }
            $str = implode('_', $lowerCasedStr);
        }

        return $str;
    }
892680
protected function prepareChoonpuTransliteration($str)
    {
        // Consonant followed by two of the same vowel
        $consonant = 'bcdfghjklmnpqrstvwyz';

        return preg_replace_callback('/(^[' . $consonant . '])(aa|ii|uu|ee|oo)/u', function($matches){
            return $matches[1].substr($matches[2], 1) . 'ー';
        }, $str);
    }
273945
public function convertEncoding($str, $from = "ISO-8859-2", $to = "UTF-8") {

        $from = EncodingAliases::get($from);
        $to = EncodingAliases::get($to);
        
        if ($from === $to) {
            return $str;
        }

        // We don't need to do convertEncoding() if charset is ASCII (us-ascii):
        //     ASCII is a subset of UTF-8, so all ASCII files are already UTF-8 encoded
        //     https://stackoverflow.com/a/11303410
        //
        // us-ascii is the same as ASCII:
        //     ASCII is the traditional name for the encoding system; the Internet Assigned Numbers Authority (IANA)
        //     prefers the updated name US-ASCII, which clarifies that this system was developed in the US and
        //     based on the typographical symbols predominantly in use there.
        //     https://en.wikipedia.org/wiki/ASCII
        //
        // convertEncoding() function basically means convertToUtf8(), so when we convert ASCII string into UTF-8 it gets broken.
        if (strtolower($from) == 'us-ascii' && $to == 'UTF-8') {
            return $str;
        }

        if (function_exists('iconv') && $from != 'UTF-7' && $to != 'UTF-7') {
            return @iconv($from, $to.'//IGNORE', $str);
        } else {
            if (!$from) {
                return mb_convert_encoding($str, $to);
            }
            return mb_convert_encoding($str, $to, $from);
        }
    }
609388
public static function systemize($str, $infix = '-')
    {
        $str = self::ascii($str);
        return trim(
            preg_replace(
                '/' . preg_quote($infix, '/') . '+/',
                $infix,
                preg_replace('/[^\w-]+/', $infix, strtolower($str))
            ),
            $infix
        );
    }
776995
private static function str_replace($s,$r,$str)
    {
        if(!is_array($s)){
            $s = '!'.preg_quote($s,'!').'!u';
        }else{
            foreach ($s as $k => $v) {
                $s[$k] = '!'.preg_quote($v).'!u';
            }
        }
        return preg_replace($s,$r,$str);
    }
235546
public static function ascii($str, $srcEncoding = 'UTF-8')
    {
        // collapse soft hyphens.
        $str = str_replace(html_entity_decode('&shy;', null, 'UTF-8'), '', $str);
        return transliterator_transliterate('Any-Latin;Latin-ASCII', $str);
    }
652793
private function _out_string_encoding( &$str )
     {
        $rsc = $this->_source_result_charset();
        if( $rsc==1 ) {
            $rsstr = iconv(UCS2, 'utf-8', $str);
        }
        else if( $rsc==2 ) {
            $rsstr = iconv('utf-8', 'gb18030', iconv(UCS2, 'utf-8', $str) );
        }
        else{
            $rsstr = iconv('utf-8', 'big5', iconv(UCS2, 'utf-8', $str) );
        }
        return $rsstr;
     }
843650
public static function toKey($str)
  {
    // Remove spaces and dashes, then convert to lower case.
    $str = self::toUnderscoreSeparated($str);
    $str = mb_strtolower($str);

    return $str;
  }
652919
public static function rot47($str)
    {
        $result = '';
        foreach (str_split($str) as $char) {
            $ord = ord($char);
            $result .= (namespace\Utils::numberBetween($ord, 33, 126))
                ? chr(namespace\Utils::numberWrap($ord + 47, 33, 126))
                : $char;
        }
        return $result;
    }
1140457
protected function _replaceTranslate($str) {
		// [__]Text to translate[/__]
		if (preg_match_all('/\[__\](.*?)\[\/__\]/i', $str, $matches)) {
			foreach ($matches[0] as $i => $find) {
				$str = str_replace($find, I18n::translate($matches[1][$i]), $str);
			}
		}

		// [__d|domain]Text to translate[/__d]
		if (preg_match_all('/\[__d\|(.+?)\](.*?)\[\/__d\]/i', $str, $matches)) {
			foreach ($matches[0] as $i => $find) {
				$str = str_replace($find, I18n::translate($matches[2][$i], null, $matches[1][$i]), $str);
			}
		}

		// [__c|category]Text to translate[/__c]
		if (preg_match_all('/\[__c\|(.+?)\](.*?)\[\/__c\]/i', $str, $matches)) {
			foreach ($matches[0] as $i => $find) {
				$str = str_replace($find, I18n::translate($matches[2][$i], null, null, $matches[1][$i]), $str);
			}
		}

		return $str;
	}
90206
public static function transliterate($str)
    {
        $transliterations = array(
            'a' => 'áăâäàāąåãǻǎ',
            'ae' => 'æǽ',
            'c' => 'ćčçĉċ',
            'd' => 'ðďđ',
            'e' => 'éĕěêëėèēę',
            'g' => 'ğĝģġ',
            'h' => 'ħĥ',
            'i' => 'ıíĭîïìīįĩǐ',
            'ij' => 'ĳ',
            'j' => 'ȷĵ',
            'k' => 'ķ',
            'l' => 'ĺľļŀł',
            'n' => 'ńňņñ',
            'ng' => 'ŋ',
            'o' => 'óŏôöòőōøõǿǒơ',
            'oe' => 'œ',
            'r' => 'ŕřŗ',
            's' => 'śšşŝș',
            'ss' => 'ß',
            't' => 'ŧťţț',
            'th' => 'þ',
            'u' => 'úŭûüùűūųůũǔǖǘǚǜư',
            'w' => 'ẃŵẅẁ',
            'y' => 'ýŷÿỳ',
            'z' => 'źžż',
            
            'A' => 'ÁĂÂÄÀĀĄÅÃǺǍ',
            'Ae' => 'ÆǼ',
            'C' => 'ĆČÇĈĊ',
            'D' => 'ÐĎĐ',
            'E' => 'ÉĔĚÊËĖÈĒĘ',
            'G' => 'ĞĜĢĠ',
            'H' => 'ĦĤ',
            'I' => 'IÍĬÎÏİÌĪĮĨǏ',
            'Ij' => 'Ĳ',
            'J' => 'Ĵ',
            'K' => 'Ķ',
            'L' => 'ĹĽĻĿŁ',
            'N' => 'ŃŇŅÑ',
            'Ng' => 'Ŋ',
            'O' => 'ÓŎÔÖÒŐŌØÕǾǑƠ',
            'Oe' => 'Œ',
            'R' => 'ŔŘŖ',
            'S' => 'ŚŠŞŜȘ',
            // 'SS' => 'SS',
            'T' => 'ŦŤŢȚ',
            'Th' => 'Þ',
            'U' => 'ÚŬÛÜÙŰŪŲŮŨǓǕǗǙǛƯ',
            'W' => 'ẂŴẄẀ',
            'Y' => 'ÝŶŸỲ',
            'Z' => 'ŹŽŻ',
            
            '1' => '¹',
            '2' => '²',
            '3' => '³',
            '4' => '⁴',
        );
        
        $originals = array_map(function($el){
            return '/[' . $el . ']/u';
        }, array_values($transliterations));
        $out = preg_replace($originals, array_keys($transliterations), $str);
        return $out;
    }
1075830
private function transliterateGerman($s)
    {
        $table = array(
            //'ä' => 'ae', //messes up with slovak -> they have ä -> a
            'ë' => 'e',
            'ï' => 'i',
            'ö' => 'oe',
            'ü' => 'ue',
            'Ä' => 'Ae',
            'Ë' => 'E',
            'Ï' => 'I',
            'Ö' => 'Oe',
            'Ü' => 'Ue',
            'ß' => 'ss',
        );
        return strtr($s, $table);
    }
661090
public static function convertEncoding( $str, $to_encoding = NULL, $from_encoding = NULL )
    {
        if ( is_string($str) && $to_encoding ){
            // エンコードあり
            return mb_convert_encoding($str,$to_encoding, $from_encoding);
        }
        // エンコード無し
        return $str;
    }
802917
public function lettering($str)
  {
    $output = '';
    $array = str_split($str);
    $idx = 1;

    foreach ($array as $letter) {
      $output .= '<span class="char' . $idx++ . '">' . $letter . '</span>';
    }

    return $output;
  }
332267
private function unescapeLatinCharacters($str)
    {
        if ($this->latinCharacters) {
            $str = vsprintf($str, $this->latinCharacters);
            $this->latinCharacters = array();
        }

        return $str;
    }