0

How can I force encode this: Al-F\u0026#257;ti\u0026#293;ah to Al-Fātiĥah

I tried .encode!('UTF-16', :undef => :replace, :invalid => :replace, :replace => "") and force_encoding("UTF-8") with no luck

Mohamed El Mahallawy
  • 13,024
  • 13
  • 52
  • 84

1 Answers1

1

That text seems to include HTML or XML entities.

Try

require "cgi/util"
CGI.unescapeHTML("Al-F\u0026#257;ti\u0026#293;ah")

or

# gem install nokogiri
require "nokogiri"
Nokogiri::XML.fragment("Al-F\u0026#257;ti\u0026#293;ah").text

See: Converting escaped XML entities back into UTF-8

Community
  • 1
  • 1
labocho
  • 231
  • 1
  • 4