I have a website that is working fine, except I cannot get it to print
out characters other than plain text. Characters such as ', :, " and
others like degrees print with the dreaded black diamond with a ?
inside.
Anyone has any idea as to how I might overcome this.
I want to have my website printing out the above special characters.
I use MySql database to store text which is printed to the screen.
This is setup with coliation = Latin1_general_ci, but changing this
does not seem to mater.
I have a website that is working fine, except I cannot get it to print
out characters other than plain text.
*Any* character is plain text.
Characters such as ', :, " and
others like degrees print with the dreaded black diamond with a ?
inside.
Then your actual encoding is Latin-1 (8859-1), but the browser is trying
to process it as if it were UTF-8.
Anyone has any idea as to how I might overcome this.
I want to have my website printing out the above special characters.
The concept of "special character" is not really a useful one. They're
just characters.
I use MySql database to store text which is printed to the screen.
This is setup with coliation = Latin1_general_ci, but changing this
does not seem to mater.
Collation may not matter, but encoding does. Make sure your DB encoding
is set to something reasonable for your data (generally UTF-8 is a good
choice). MySQL also has the option of setting column encodings; make
sure those are correct.
I have solved the problem. It was a simple problem, but its cause was
rather involved so I will try and explain the process and knowledge I
gained in solving it below:-
I first solved it on my home computer copy of my website (which I
have now re-written the website in ROR 3 and Ruby1.9.2, but that will
be another thread.)
I wrote a my.cnf file in my ./etc folder. I thought that that was part
of the cure, but as I did not restart my server it did not have any
effect until the following day when I restarted and my local copy did
not start for two reasons. One was that Mysql server on my computer
had stopped and (/tmp/mysql.sock) disappeared. I had to go to the
preferences and restart it. The other was that both ports were set to
3000 in my my.cnf file. copy below:-
[client]
port = 3000
socket = /tmp/mysql.sock
default-character-set=utf8
I think what cured it was setting encoding utf8 in my database.yml.
copy below:-
development:
adapter: mysql
database: donsgarden
username: root
password:
socket: /tmp/mysql.sock
encoding: utf8
I then went to my shared host and asked them to change mysql to utf8
(which they could not do) so I am stuck with Latin1 and collation
Latin1_swedish_ci :
I then found out that phpMyAdmin was reporting my settings wrongly,
because it only uses utf8 it only reports utf8 and collation
utf8_general_ci even though Mysql was using Latin1 and collation
Latin1_swedish_ci throughout. (This caused a lot of head scratching)
The following day my website crashed and my host moved it to a new
service and all was magically solved.
I think what happened was that when it restarted the encoding: utf8 in
the database.yml kicked in.
On my shared host my.cnf file was not changed.
The only problem is that old data saved in my database is printed
incorrectly, but new data entered in phpMyAdmin is saved and printed
correctly.
Perhaps if I changed my.cnf on my shared host (via ssh access) to
include utf8 all the data (old and new as on my home copy) would print
correctly.
I am leaving things as they are as I can live with re-saving the
little old data I have
Don