# Convert html to plain text in ruby

**URL:** <https://www.ruby-forum.com/t/convert-html-to-plain-text-in-ruby/149989>\
**Category:** Rails\
**Created:** [October 2, 2008, 12:32am UTC](https://www.ruby-forum.com/t/convert-html-to-plain-text-in-ruby/149989 "2008-10-02T00:32:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 2, 2008, 12:32am UTC](https://www.ruby-forum.com/t/convert-html-to-plain-text-in-ruby/149989/1 "2008-10-02T00:32:17Z")

</div>

Hi,

I’m looking for a way to convert html to plain text.  
Now, I know about strip\_tags, but - as the name says - that only  
strips the tags.

What I need is to get stuff like & and \< back to & and \< too.  
Any help?

Thanks,  
Mathijs

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 2, 2008, 8:27pm UTC](https://www.ruby-forum.com/t/convert-html-to-plain-text-in-ruby/149989/2 "2008-10-02T20:27:25Z")

</div>

You could use some regexp and the hash ERB::Util::HTML\_ESCAPE to  
return the unescaped versions of the characters.

- Richard

On Oct 1, 3:31 pm, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
