Special characters in ERB

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

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

single quotes

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.

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