justclint
9/21/2016 - 5:48 PM

php - seo url - lowercase dashes

function clean_url($string) {
    // Make lower case.
    $string = strtolower( $string) ;
    // Make alphanumeric. Remove all characters.
    $string = preg_replace("/[^a-z0-9_\s-]/", "", $string);
    // Clean multiple dashes and whitespace.
    $string = preg_replace("/[\s-]+/", " ", $string);
    //Convert whitespaces and underscore to dash.
    $string = preg_replace("/[\s_]/", "-", $string);
    return $string;
}