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

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.