I’d like to take a string, strip it of all non-alphanumeric characters and convert all spaces into dashes.
I’d like to take a string, strip it of all non-alphanumeric characters and convert
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I use the following code whenever I want to convert headlines or other strings to URL slugs. It does everything you ask for by using RegEx to convert any string to alphanumeric characters and hyphens.
If you are going to use the code for generating URL slugs, then you might want to consider adding a little extra code to cut it after 80 characters or so.