Slug Para PHP

Funcion que retorna el slug de una cadena de caracteres. E.j. dominio.com/url-amigable donde el slug es url-amigable, lo que tienes que hacer es pasar un string como “URL Amigable” para que retorne el slug.

function slug($string) {
    $characters = array(
        "Á" => "A", "Ç" => "c", "É" => "e", "Í" => "i", "Ñ" => "n", "Ó" => "o", "Ú" => "u", 
	"á" => "a", "ç" => "c", "é" => "e", "í" => "i", "ñ" => "n", "ó" => "o", "ú" => "u",
	"à" => "a", "è" => "e", "ì" => "i", "ò" => "o", "ù" => "u"
    );
	
    $string = strtr($string, $characters); 
    $string = strtolower(trim($string));
    $string = preg_replace("/[^a-z0-9-]/", "-", $string);
    $string = preg_replace("/-+/", "-", $string);
	
    if(substr($string, strlen($string) - 1, strlen($string)) === "-") {
        $string = substr($string, 0, strlen($string) - 1);
    }
	
    return $string;
}