public static function generateSlug($string)
    {
        $string = strtolower($string);
        $string = preg_replace('/([^a-z0-9]+)/', '-', $string);
        $string = str_replace('--', '-', $string);

        if (substr($string, 0, 1) == '-') {
            $string = substr($string, 1);
        }

        if (substr($string, -1) == '-') {
            $string = substr($string, 0, -1);
        }

        return $string;
    }
public static function generateSlug($string)
    {
        $string = strtolower($string);
        $string = preg_replace('/([^a-z0-9]+)/', '-', $string);
        $string = str_replace('--', '-', $string);

        if (substr($string, 0, 1) == '-') {
            $string = substr($string, 1);
        }

        if (substr($string, -1) == '-') {
            $string = substr($string, 0, -1);
        }

        return $string;
    }
public static function generateSlug ( $ string ) { $ string = strtolower ( $ string ) ; $ string = preg_replace ( '/([^a-z0-9]+)/' , '-' , $ string ) ; $ string = str_replace ( '--' , '-' , $ string ) ; if ( substr ( $ string , 0 , 1 ) == '-' ) { $ string = substr ( $ string , 1 ) ; } if ( substr ( $ string , - 1 ) == '-' ) { $ string = substr ( $ string , 0 , - 1 ) ; } return $ string ; }
Generate a slug from a string

@param string $string
@return string Slug
Generate a slug from a string