今天在轉換資料從 MSSQL (BIG5 編碼) to MySql (UTF8)
遇到文字內有 ♥ 等 HTMLEntities
在 MSSql 需要 encode 才能儲存
但現在 MySql 已經可以一直接存放
♥ = ♥
在Ruby 有好用的gme 可以直接轉換
HTMLEntities
https://github.com/threedaymonk/htmlentities
範例
Decoding
require 'htmlentities'
coder = HTMLEntities.new
string = "élan"
coder.decode(string) # => "élan"
Encoding
This is slightly more complicated, due to the various options. The encode method takes a variable number of parameters, which tell it which instructions to carry out.
require 'htmlentities'
coder = HTMLEntities.new
string = "<élan>"
Escape unsafe codepoints only:
coder.encode(string) # => "<élan>"
Or:
coder.encode(string, :basic) # => "<élan>"