src/StringUtils.php
public static function slugify($string)
    {
        if (!is_string($string)) {
            $type = gettype($string);
            throw new \InvalidArgumentException("Given argument is a $type, expected string.");
        }

        if (empty($string)) {
            throw new \InvalidArgumentException("Cannot slugify an empty string.");
        }

        // Replace some language-specific characters which are not handled by
        // iconv transliteration satisfactorily.
        $string = strtr($string, CharacterMap::get());

        // Replace non-alphanumeric characters by "-"
        $string = preg_replace('/[^\\p{L}\\d]+/u', '-', $string);

        // Trim
        $string = trim($string, '-');

        // Transliterate
        $string = iconv('utf-8', 'ASCII//TRANSLIT', $string);

        // Lowercase
        $string = strtolower($string);

        // Remove unwanted characters
        $string = preg_replace('/[^-\w]+/', '', $string);

        return $string;
    }
public static function slugify($string)
    {
        if (!is_string($string)) {
            $type = gettype($string);
            throw new \InvalidArgumentException("Given argument is a $type, expected string.");
        }

        if (empty($string)) {
            throw new \InvalidArgumentException("Cannot slugify an empty string.");
        }

        // Replace some language-specific characters which are not handled by
        // iconv transliteration satisfactorily.
        $string = strtr($string, CharacterMap::get());

        // Replace non-alphanumeric characters by "-"
        $string = preg_replace('/[^\\p{L}\\d]+/u', '-', $string);

        // Trim
        $string = trim($string, '-');

        // Transliterate
        $string = iconv('utf-8', 'ASCII//TRANSLIT', $string);

        // Lowercase
        $string = strtolower($string);

        // Remove unwanted characters
        $string = preg_replace('/[^-\w]+/', '', $string);

        return $string;
    }
public static function slugify ( $ string ) { if ( ! is_string ( $ string ) ) { $ type = gettype ( $ string ) ; throw new \ InvalidArgumentException ( "Given argument is a $type, expected string." ) ; } if ( empty ( $ string ) ) { throw new \ InvalidArgumentException ( "Cannot slugify an empty string." ) ; } // Replace some language-specific characters which are not handled by // iconv transliteration satisfactorily. $ string = strtr ( $ string , CharacterMap :: get ( ) ) ; // Replace non-alphanumeric characters by "-" $ string = preg_replace ( '/[^\\p{L}\\d]+/u' , '-' , $ string ) ; // Trim $ string = trim ( $ string , '-' ) ; // Transliterate $ string = iconv ( 'utf-8' , 'ASCII//TRANSLIT' , $ string ) ; // Lowercase $ string = strtolower ( $ string ) ; // Remove unwanted characters $ string = preg_replace ( '/[^-\w]+/' , '' , $ string ) ; return $ string ; }
Returns a slugified version of the string.

Converts the given string into a string consisting only of lowecase
ASCII characters and dashes (-). Used for constructing URLs.

@param  string $string String to convert.

@return string         Slugified string.

@throws InvalidArgumentException If given argument is not a string or is
empty.
Returns a slugified version of the string .