How to convert unicode string to ascii to make a nice string for a friendly url?
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.
There is only a short list of characters that can be safely carried through in a path component of a URL.
All the other characters will have to be either removed (if you’re creating a “slug”) or escaped.
Removal can be done with the regex
/[^a-zA-Z0-9-._~]/.Escaping can be done with
encodeURIComponent().If you wish to achieve an equivalent of ICONV transliteration (that is, turning
éintoeand€intoEUR), you’ll have to do your own, although you can leverage existing solutions and perhaps transform a transliteration table to JS format.