How to remove dot(.) comma (,) from name

I am trying to make a URL from a user name but I have some problems doing so. Here are some examples of what I am trying to do:

User Name = J.R.R. Tolkien
I want To convert Like THis = j-r-r-tolkien


User Name = Barrie M. Osborne
Convert = barrie-m-osborne

User Name = William Broyles Jr.
Convert = william-broyles-jr


User Name Comma (,) = Harry Waters, Jr.
Convert = harry-waters-jr

This is my code:

'name_slug' => strtolower(str_replace('.', '', str_replace(' ', '-', empty($name) ? '' : $name))),

This just doesn’t work for all cases. Can anyone help?