Built-in Methods to Encode/Decode HTML?

Are there any built-in methods in either Ruby or Rails to do what this
library does (i.e. encode/decode HTML)?
http://htmlentities.rubyforge.org/

The above library works beautifully but I just expected this sort of
functionality to be part of Ruby/Rails since languages such as PHP,
Java, etc. have this as part of their core functionality.

Thanks.

You can do it with URI

name = “Ruby P.ming Language”
url = “Example Domain” + URI.escape(name)
puts url # Example Domain

On Aug 24, 1:38 pm, Ben K. [email protected]

Ben K. wrote:

Are there any built-in methods in either Ruby or Rails to do what this
library does (i.e. encode/decode HTML)?
http://htmlentities.rubyforge.org/

The above library works beautifully but I just expected this sort of
functionality to be part of Ruby/Rails since languages such as PHP,
Java, etc. have this as part of their core functionality.

For encoding, rails provides h() which is an alias to html_escape(). For
decoding it’s best to use the HTMLEntities library that you already
found. Though you can use the stock CGI::unescape(), that will only
decode numerical HTML entities but no named ones.


Roderick van Domburg

Thanks, Roderick and Pedro. I think I will stick with HTMLEntities for
now :slight_smile:

Anil

Roderick van Domburg wrote:

Ben K. wrote:

Are there any built-in methods in either Ruby or Rails to do what this
library does (i.e. encode/decode HTML)?
http://htmlentities.rubyforge.org/

The above library works beautifully but I just expected this sort of
functionality to be part of Ruby/Rails since languages such as PHP,
Java, etc. have this as part of their core functionality.

For encoding, rails provides h() which is an alias to html_escape(). For
decoding it’s best to use the HTMLEntities library that you already
found. Though you can use the stock CGI::unescape(), that will only
decode numerical HTML entities but no named ones.


Roderick van Domburg
http://www.nedforce.nl