# Convert htmlspecial characters using ruby

**URL:** <https://rubytalk.org/t/convert-htmlspecial-characters-using-ruby/38975>\
**Category:** ruby-talk\
**Created:** [11 July 2007 07:11 UTC](https://rubytalk.org/t/convert-htmlspecial-characters-using-ruby/38975 "2007-07-11T07:11:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![geetha](https://avatars.discourse-cdn.com/v4/letter/g/f08c70/32.png) [@geetha](https://rubytalk.org/u/geetha)\
**Post date:** [11 July 2007 07:11 UTC](https://rubytalk.org/t/convert-htmlspecial-characters-using-ruby/38975/1 "2007-07-11T07:11:19Z")

</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:** ![Hemant\_Kumar](https://avatars.discourse-cdn.com/v4/letter/h/46a35a/32.png) [@Hemant\_Kumar](https://rubytalk.org/u/Hemant_Kumar)\
**Post date:** [11 July 2007 09:06 UTC](https://rubytalk.org/t/convert-htmlspecial-characters-using-ruby/38975/2 "2007-07-11T09:06:14Z")

</div>

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

CGI::escapeHTML('Usage: foo "bar" \<baz\>')  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# =\> "Usage: foo &quot;bar&quot; &lt;baz&gt;"

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.

> **···**
>
> On 7/11/07, geetha \<sangeetha.geethu05@gmail.com\> wrote:
> 
> > 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:** ![Marcin\_Raczkowski1](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@Marcin\_Raczkowski1](https://rubytalk.org/u/Marcin_Raczkowski1)\
**Post date:** [11 July 2007 09:17 UTC](https://rubytalk.org/t/convert-htmlspecial-characters-using-ruby/38975/3 "2007-07-11T09:17:52Z")

</div>

also ERB::h might help ^^

> **···**
>
> On Wednesday 11 July 2007 09:06, hemant wrote:
> 
> > On 7/11/07, geetha \<sangeetha.geethu05@gmail.com\> 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" \<baz\>')  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# =\> "Usage: foo &quot;bar&quot; &lt;baz&gt;"
> > 
> > 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.
> 
> --  
> Marcin Raczkowski  
> ---  
> Friends teach what you should know  
> Enemies Teach what you have to know
