src/Utilities/Miscellaneous.php
public static function toLatin($string, $lowerCaseHuman = true, $replacementChar = '-')
    {
        if (is_string($string)) {
            $string = trim($string);
        }

        /*
         * Empty value?
         * Nothing to do
         */
        if (empty($string)) {
            return '';
        }

        $converter = Transliterator::create('Latin-ASCII;');

        /*
         * Oops, cannot instantiate converter
         * Nothing to do
         */
        if (null === $converter) {
            return '';
        }

        $converted = $converter->transliterate($string);

        // Make the string lowercase and human-readable
        if ($lowerCaseHuman) {
            $matches = [];
            $matchCount = preg_match_all('|[A-Z]{1}[^A-Z]*|', $converted, $matches);

            if ($matchCount > 0) {
                $parts = $matches[0];
                $converted = mb_strtolower(implode($replacementChar, $parts));
            }
        }

        /*
         * Let's replace special characters to spaces
         * ...and finally spaces to $replacementChar
         */
        $replaced = preg_replace('|[^a-zA-Z0-9]|', ' ', $converted);

        return preg_replace('| +|', $replacementChar, trim($replaced));
    }
public static function toLatin($string, $lowerCaseHuman = true, $replacementChar = '-')
    {
        if (is_string($string)) {
            $string = trim($string);
        }

        /*
         * Empty value?
         * Nothing to do
         */
        if (empty($string)) {
            return '';
        }

        $converter = Transliterator::create('Latin-ASCII;');

        /*
         * Oops, cannot instantiate converter
         * Nothing to do
         */
        if (null === $converter) {
            return '';
        }

        $converted = $converter->transliterate($string);

        // Make the string lowercase and human-readable
        if ($lowerCaseHuman) {
            $matches = [];
            $matchCount = preg_match_all('|[A-Z]{1}[^A-Z]*|', $converted, $matches);

            if ($matchCount > 0) {
                $parts = $matches[0];
                $converted = mb_strtolower(implode($replacementChar, $parts));
            }
        }

        /*
         * Let's replace special characters to spaces
         * ...and finally spaces to $replacementChar
         */
        $replaced = preg_replace('|[^a-zA-Z0-9]|', ' ', $converted);

        return preg_replace('| +|', $replacementChar, trim($replaced));
    }
public static function toLatin ( $ string , $ lowerCaseHuman = true , $ replacementChar = '-' ) { if ( is_string ( $ string ) ) { $ string = trim ( $ string ) ; } /*
         * Empty value?
         * Nothing to do
         */ if ( empty ( $ string ) ) { return '' ; } $ converter = Transliterator :: create ( 'Latin-ASCII;' ) ; /*
         * Oops, cannot instantiate converter
         * Nothing to do
         */ if ( null === $ converter ) { return '' ; } $ converted = $ converter -> transliterate ( $ string ) ; // Make the string lowercase and human-readable if ( $ lowerCaseHuman ) { $ matches = [ ] ; $ matchCount = preg_match_all ( '|[A-Z]{1}[^A-Z]*|' , $ converted , $ matches ) ; if ( $ matchCount > 0 ) { $ parts = $ matches [ 0 ] ; $ converted = mb_strtolower ( implode ( $ replacementChar , $ parts ) ) ; } } /*
         * Let's replace special characters to spaces
         * ...and finally spaces to $replacementChar
         */ $ replaced = preg_replace ( '|[^a-zA-Z0-9]|' , ' ' , $ converted ) ; return preg_replace ( '| +|' , $ replacementChar , trim ( $ replaced ) ) ; }
Converts given string characters to latin characters

@param string $string          String to convert
@param bool   $lowerCaseHuman  (optional) If is set to true, converted string is returned as lowercase and
human-readable. Otherwise - as original.
@param string $replacementChar (optional) Replacement character for all non-latin characters and uppercase
letters, if 2nd argument is set to true
@return string
Converts given string characters to latin characters