# CGI unescapeHTML to escape code '&# 8211;'

**URL:** <https://www.ruby-forum.com/t/cgi-unescapehtml-to-escape-code-8211/147962>\
**Category:** Ruby\
**Created:** [September 7, 2008, 6:51pm UTC](https://www.ruby-forum.com/t/cgi-unescapehtml-to-escape-code-8211/147962 "2008-09-07T18:51:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shashank\_hi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7bcc69/32.png) [@shashank\_hi](https://www.ruby-forum.com/u/shashank_hi)\
**Post date:** [September 7, 2008, 6:51pm UTC](https://www.ruby-forum.com/t/cgi-unescapehtml-to-escape-code-8211/147962/1 "2008-09-07T18:51:50Z")

</div>

I’m reading an XML file that has the html codes for hyphens and stuff  
like that. I tried escaping hyphen’s html code, which is ‘&# 8211;’  
(space added to avoid interpretation) with the CGI::unescapeHTML  
function. But it did not escape it. Is there a way to escape such codes?

---

<div class="post-metadata">

**Author:** ![shashank\_hi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7bcc69/32.png) [@shashank\_hi](https://www.ruby-forum.com/u/shashank_hi)\
**Post date:** [September 7, 2008, 8:40pm UTC](https://www.ruby-forum.com/t/cgi-unescapehtml-to-escape-code-8211/147962/2 "2008-09-07T20:40:03Z")

</div>

-------- Original-Nachricht --------

> Datum: Mon, 8 Sep 2008 01:45:44 +0900  
> Von: Shashank A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> An: removed\_email\_address@domain.invalid  
> Betreff: CGI unescapeHTML to escape code '&# 8211;'

> ## I’m reading an XML file that has the html codes for hyphens and stuff like that. I tried escaping hyphen’s html code, which is ‘&# 8211;’ (space added to avoid interpretation) with the CGI::unescapeHTML function. But it did not escape it. Is there a way to escape such codes?
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

Dear Shashank,

have a look at htmlentites ([http://htmlentities.rubyforge.org/](http://htmlentities.rubyforge.org/)).  
Maybe you can re-escape its results using CGI.escape, if that’s needed.

Best regards,

Axel

---

<div class="post-metadata">

**Author:** ![shashank\_hi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7bcc69/32.png) [@shashank\_hi](https://www.ruby-forum.com/u/shashank_hi)\
**Post date:** [September 10, 2008, 7:13pm UTC](https://www.ruby-forum.com/t/cgi-unescapehtml-to-escape-code-8211/147962/3 "2008-09-10T19:13:40Z")

</div>

Axel E. wrote:

> Dear Shashank,
> 
> have a look at htmlentites ([http://htmlentities.rubyforge.org/](http://htmlentities.rubyforge.org/)).  
> Maybe you can re-escape its results using CGI.escape, if that’s needed.
> 
> Best regards,
> 
> Axel

Thanks, this is what I was looking for. 🙂
