How to create unicode slug for unicode title?

烈酒焚心 提交于 2019-12-08 03:26:06

问题


I want to sanitize blog titles with unicode characters in url. I need to replace invalid characters and spaces with "-" for better seo rewriting like this.

        http://example.com/это-моя-хорошая

Can anyone have any idea how to do it?


回答1:


You can use this algorithm for an SEO-friendly Unicode URL:

  1. Convert the text to Unicode Normalization Form C, i.e. precomposed characters.
  2. Use a regular expression with Unicode character classes to replace each non-letter non-digit character with a space.
  3. Remove leading, trailing and double spaces.
  4. Shorten.
  5. Replace spaces with hyphens.


来源:https://stackoverflow.com/questions/9511254/how-to-create-unicode-slug-for-unicode-title

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!