function seo($input)
{
    //remove single quote and dash
    $input = str_replace(array("'", "-"), "", $input); 

    //convert to lowercase
    $input = mb_convert_case($input, MB_CASE_LOWER, "UTF-8"); 

    //replace everything non an with dashes
    $input = preg_replace("#[^a-zA-Z0-9]+#", "-", $input); 

    //replace multiple dashes with one
    $input = preg_replace("#(-){2,}#", "$1", $input);

    //trim dashes from beginning and end of string if any
    $input = trim($input, "-"); 
    
    //voila
    return $input; 
}

OP:
echo seo(“Tom’s Fish & Chips”); //toms-fish-chips
echo seo(“1-2-3 Pizza”); //123-pizza

Leave a reply