DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Translate Multibyte Strings To Be Url Safe

10.15.2008
| 5014 views |
  • submit to reddit
        
class String
  def to_permalink
      (Iconv.new('US-ASCII//TRANSLIT', 'utf-8').iconv self).gsub(/[^\w\s\-\—]/,'').gsub(/[^\w]|[\_]/,' ').split.join('-').downcase
  end
end
    

Comments

Snippets Manager replied on Sat, 2008/10/25 - 4:54pm

Awesome! Thanks.