# Convert htmlspecial characters using ruby

**URL:** <https://www.ruby-forum.com/t/convert-htmlspecial-characters-using-ruby/109066>\
**Category:** Ruby\
**Created:** [July 11, 2007, 9:12am UTC](https://www.ruby-forum.com/t/convert-htmlspecial-characters-using-ruby/109066 "2007-07-11T09:12:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![geetha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f08c70/32.png) [@geetha](https://www.ruby-forum.com/u/geetha)\
**Post date:** [July 11, 2007, 9:12am UTC](https://www.ruby-forum.com/t/convert-htmlspecial-characters-using-ruby/109066/1 "2007-07-11T09:12:00Z")

</div>

hi,

I have to decode the html special character using ruby,  
if any function is there like php htmlspecialchars\_decode ().

thanks,  
sangeetha.S

---

<div class="post-metadata">

**Author:** ![geetha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f08c70/32.png) [@geetha](https://www.ruby-forum.com/u/geetha)\
**Post date:** [July 11, 2007, 11:07am UTC](https://www.ruby-forum.com/t/convert-htmlspecial-characters-using-ruby/109066/2 "2007-07-11T11:07:17Z")

</div>

On 7/11/07, geetha [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> hi,
> 
> I have to decode the html special character using ruby,  
> if any function is there like php htmlspecialchars\_decode ().
> 
> thanks,  
> sangeetha.S

If you want to escape HTML special charcaters then i guess following  
would work:

CGI::escapeHTML(‘Usage: foo “bar” ’)  
# =\> “Usage: foo "bar" \<baz\>”

If thats not what you want, please look into documentation of CGI  
class and i think you would find method that you are looking for.

---

<div class="post-metadata">

**Author:** ![geetha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f08c70/32.png) [@geetha](https://www.ruby-forum.com/u/geetha)\
**Post date:** [July 11, 2007, 11:18am UTC](https://www.ruby-forum.com/t/convert-htmlspecial-characters-using-ruby/109066/3 "2007-07-11T11:18:20Z")

</div>

On Wednesday 11 July 2007 09:06, hemant wrote:

> If you want to escape HTML special charcaters then i guess following would  
> work:
> 
> CGI::escapeHTML('Usage: foo “bar” ')  
> # =\> “Usage: foo “bar” \<baz\>”
> 
> If thats not what you want, please look into documentation of CGI  
> class and i think you would find method that you are looking for.  
> also ERB::h might help ^^
