# Special characters in ERB

**URL:** <https://www.ruby-forum.com/t/special-characters-in-erb/82063>\
**Category:** Rails\
**Created:** [March 15, 2006, 3:59am UTC](https://www.ruby-forum.com/t/special-characters-in-erb/82063 "2006-03-15T03:59:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jennyw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7feea3/32.png) [@jennyw](https://www.ruby-forum.com/u/jennyw)\
**Post date:** [March 15, 2006, 3:59am UTC](https://www.ruby-forum.com/t/special-characters-in-erb/82063/1 "2006-03-15T03:59:24Z")

</div>

I’m pulling text out of a database that contains special characters,  
like the trademark sign. For example, a typical string might be like  
this:

string\_from\_database =\> “Some Special Brand\231 is for sale this  
Thursday through Friday.”

The \231 is the trademark sign ™. ERB converts this to question  
marks. So, my question is – how can I get it to display the trademark  
sign? They have another Web site using PHP which just sends what’s in  
the database out to the Web without substitutions. This would work  
better than the substitution to ? signs, but it’d be even better to  
convert it to the appropriate HTML entity.

Does anyone know of a plug-in or anything that will do this for the  
trademark symbol and other characters? Or a way to bypass ERB’s  
substitution?

Thanks!

Jen

---

<div class="post-metadata">

**Author:** ![jennyw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7feea3/32.png) [@jennyw](https://www.ruby-forum.com/u/jennyw)\
**Post date:** [March 15, 2006, 11:42am UTC](https://www.ruby-forum.com/t/special-characters-in-erb/82063/2 "2006-03-15T11:42:12Z")

</div>

try this :  
string\_from\_database =\> ‘Some Special Brand\231 is for sale this  
Thursday through Friday.’

single quotes

---

<div class="post-metadata">

**Author:** ![jennyw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7feea3/32.png) [@jennyw](https://www.ruby-forum.com/u/jennyw)\
**Post date:** [March 15, 2006, 12:02pm UTC](https://www.ruby-forum.com/t/special-characters-in-erb/82063/3 "2006-03-15T12:02:03Z")

</div>

jennyw wrote:

> better than the substitution to ? signs, but it’d be even better to  
> convert it to the appropriate HTML entity.
> 
> Does anyone know of a plug-in or anything that will do this for the  
> trademark symbol and other characters? Or a way to bypass ERB’s  
> substitution?  
> Sounds to me like you’ve got your character sets in a twist. \231  
> certainly isn’t a trademark sign in UTF-8, and question-mark  
> substitution is what browsers do when they come across a character they  
> don’t understand in the current context. I don’t believe ERb does any  
> substitution like that at all. Try explicitly setting the character set  
> of your page to ISO-8859-1 (or CP-1252, for that matter… I think  
> they’re the same in that range) in the HTML and in the HTTP  
> header, and see how it comes out.

---

<div class="post-metadata">

**Author:** ![jennyw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7feea3/32.png) [@jennyw](https://www.ruby-forum.com/u/jennyw)\
**Post date:** [March 15, 2006, 10:04pm UTC](https://www.ruby-forum.com/t/special-characters-in-erb/82063/4 "2006-03-15T22:04:29Z")

</div>

Alex Y. wrote:

> Sounds to me like you’ve got your character sets in a twist. \231  
> certainly isn’t a trademark sign in UTF-8, and question-mark  
> substitution is what browsers do when they come across a character  
> they don’t understand in the current context. I don’t believe ERb  
> does any substitution like that at all. Try explicitly setting the  
> character set of your page to ISO-8859-1 (or CP-1252, for that  
> matter… I think they’re the same in that range) in the HTML   
> and in the HTTP header, and see how it comes out.  
> Thanks, Alex. This was it!

FYI, at first I tried:

> headers[“Content-Type”] = “text/html”

which thew me for a loop at first, since even though I don’t specify a  
charset above it shows up as UTF-8 (I tried it that way because that’s  
what the original PHP Web site did). Then I realized that Rails (or  
something) adds charset after “text/html” whether you set it or not.  
Adding “; charset=ISO-8859-1” worked just fine.

Jen
