src/StringUtils.php
public static function translit($string, $substChar = '?', $trim = true, $removeDuplicates = true)
    {
        // Cast scalars to strings, if non-scalar is given throw an exception
        if (!is_string($string)) {
            if (is_scalar($string)) {
                $string = (string) $string;
            } else {
                $type = gettype($string);
                throw new \InvalidArgumentException(__METHOD__ . "() expects parameter 1 to be string, $type given");
            }
        }

        // Replace language-specific characters
        $string = strtr($string, CharacterMap::get());

        // Replace any leftover non-ASCII characters by the replacement char.
        $string = preg_replace("/[^\\w]/", $substChar, $string);

        if ($trim) {
            $string = trim($string, $substChar);
        }

        if ($removeDuplicates) {
            $string = preg_replace("/\\{$substChar}+/", $substChar, $string);
        }

        return $string;
    }
public static function translit($string, $substChar = '?', $trim = true, $removeDuplicates = true)
    {
        // Cast scalars to strings, if non-scalar is given throw an exception
        if (!is_string($string)) {
            if (is_scalar($string)) {
                $string = (string) $string;
            } else {
                $type = gettype($string);
                throw new \InvalidArgumentException(__METHOD__ . "() expects parameter 1 to be string, $type given");
            }
        }

        // Replace language-specific characters
        $string = strtr($string, CharacterMap::get());

        // Replace any leftover non-ASCII characters by the replacement char.
        $string = preg_replace("/[^\\w]/", $substChar, $string);

        if ($trim) {
            $string = trim($string, $substChar);
        }

        if ($removeDuplicates) {
            $string = preg_replace("/\\{$substChar}+/", $substChar, $string);
        }

        return $string;
    }
public static function translit ( $ string , $ substChar = '?' , $ trim = true , $ removeDuplicates = true ) { // Cast scalars to strings, if non-scalar is given throw an exception if ( ! is_string ( $ string ) ) { if ( is_scalar ( $ string ) ) { $ string = ( string ) $ string ; } else { $ type = gettype ( $ string ) ; throw new \ InvalidArgumentException ( __METHOD__ . "() expects parameter 1 to be string, $type given" ) ; } } // Replace language-specific characters $ string = strtr ( $ string , CharacterMap :: get ( ) ) ; // Replace any leftover non-ASCII characters by the replacement char. $ string = preg_replace ( "/[^\\w]/" , $ substChar , $ string ) ; if ( $ trim ) { $ string = trim ( $ string , $ substChar ) ; } if ( $ removeDuplicates ) { $ string = preg_replace ( "/\\{$substChar}+/" , $ substChar , $ string ) ; } return $ string ; }
Transliterates an UTF8 string to printable ASCII characters.

@param  string  $string    The string to transliterate.
@param  string  $substChar The character to use for characters which
cannot be transliterated.
@param  boolean $trim      Whether to trim any subst characters from
beginning and end of string.
@param  boolean $removeDuplicates Whether to remove duplicate subst chars
with only one.

@return string  The transliterated string.
Transliterates an UTF8 string to printable ASCII characters .