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

**URL:** <https://rubytalk.org/t/cgi-unescapehtml-to-escape-code-8211/48925>\
**Category:** ruby-talk\
**Created:** [7 September 2008 16:45 UTC](https://rubytalk.org/t/cgi-unescapehtml-to-escape-code-8211/48925 "2008-09-07T16:45:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shashank\_Agarwal](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@Shashank\_Agarwal](https://rubytalk.org/u/Shashank_Agarwal)\
**Post date:** [7 September 2008 16:45 UTC](https://rubytalk.org/t/cgi-unescapehtml-to-escape-code-8211/48925/1 "2008-09-07T16:45:44Z")

</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?

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Axel\_Etzold](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@Axel\_Etzold](https://rubytalk.org/u/Axel_Etzold)\
**Post date:** [7 September 2008 18:31 UTC](https://rubytalk.org/t/cgi-unescapehtml-to-escape-code-8211/48925/2 "2008-09-07T18:31:38Z")

</div>

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

> Datum: Mon, 8 Sep 2008 01:45:44 +0900  
> Von: Shashank Agarwal \<shashank\_hi@yahoo.com\>  
> An: ruby-talk@ruby-lang.org  
> 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/%5C).

Dear Shashank,

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

Best regards,

Axel

> **···**
>
> --  
> GMX Kostenlose Spiele: Einfach online spielen und Spaß haben mit Pastry Passion!
> 
> > **[Aktuelle Nachrichten aus Politik, Wirtschaft & Panorama](https://www.gmx.net/magazine/news/)**
> >
> > News - Nachrichten, Kommentare, Interviews und Hintergründe zu nationaler und internationaler Politik, Sport und Wirtschaft sowie das aktuelle Wetter und Panorama.

---

<div class="post-metadata">

**Author:** ![Shashank\_Agarwal](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@Shashank\_Agarwal](https://rubytalk.org/u/Shashank_Agarwal)\
**Post date:** [10 September 2008 17:07 UTC](https://rubytalk.org/t/cgi-unescapehtml-to-escape-code-8211/48925/3 "2008-09-10T17:07:34Z")

</div>

Axel Etzold wrote:

> Dear Shashank,
> 
> have a look at htmlentites ([http://htmlentities.rubyforge.org/\](http://htmlentities.rubyforge.org/%5C)).  
> 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. 🙂

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
