Forum: Ruby on Rails Method to remove html escape characters from strings

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Karl (Guest)
on 2009-04-08 22:43
(Received via mailing list)
Is there a convenient way of removing html escape characters from
Strings? I could do using reg exp as in:

=> "hello & goodbye"
>> "hello & goodbye".gsub(/&/, "&")
=> "hello & goodbye"

but I figured there might be a better way.

thx.
Philip H. (Guest)
on 2009-04-08 23:05
(Received via mailing list)
> Is there a convenient way of removing html escape characters from
> Strings? I could do using reg exp as in:
>
> => "hello & goodbye"
>>> "hello & goodbye".gsub(/&/, "&")
> => "hello & goodbye"
>
> but I figured there might be a better way.

require 'CGI'>> require 'CGI'
=> true
 >> CGI::unescapeHTML("hello & goodbye "bar" <baz>")
=> "hello & goodbye "bar" <baz>"
Karl B. (Guest)
on 2009-04-09 00:37
(Received via mailing list)
That worked.  Thanks!
Freddy A. (Guest)
on 2009-04-09 00:58
(Received via mailing list)
If found this little snap that I got in my application_helper

  def remove_html_tags(str)
    str.gsub(/<\/?[^>]*>/, "")
  end
This topic is locked and can not be replied to.