PHP Quick Convert String to Slug

    $ November 30, 2012

    Another quick and simple one:

    function to_slug($string){
        return strtolower(trim(preg_replace('/\[^A-Za-z0-9-\]+/', '-', $string)));
    }
    // Input: This is My Title // Returns: this-is-my-title