How do HTML decode a string?

I have two lines:

"50 & 60's" 

and

 "50 & 60's" 

and they must match.

Is there a way that I can do something for a string, maybe decode HTML before comparing?

+4
source share
2 answers

You can use CGI :: unescapeHTML or its synonym CGI::unescape_html :

 require 'cgi' CGI::unescape_html "50 & 60's" # => "50 & 60's" 
+9
source
 require 'rubygems' require 'hpricot' Hpricot("50 & 60's", :xhtml_strict => true).to_plain_text # => "50 & 60's" 
-one
source

Source: https://habr.com/ru/post/1397621/


All Articles