Chinese Characters
am 10.10.2007 00:04:53 von StevePBurgess
Hi. I need to store chinese characters and Pinyins in a mysql database
and then read them from php and using the GD library and
imagettftext() function to create an image based on a chinese ttf font
of the chinese characters.
I have tried setting the encoding in the database as UTF-8 and BIG5
but the characters display (both in MYSQL and when displayed via PHP)
as question marks.
Can anyone help?
Re: Chinese Characters
am 10.10.2007 00:30:49 von Steve
"Steve" wrote in message
news:1191967493.996319.280550@k79g2000hse.googlegroups.com.. .
> Hi. I need to store chinese characters and Pinyins in a mysql database
> and then read them from php and using the GD library and
> imagettftext() function to create an image based on a chinese ttf font
> of the chinese characters.
>
> I have tried setting the encoding in the database as UTF-8 and BIG5
> but the characters display (both in MYSQL and when displayed via PHP)
> as question marks.
>
> Can anyone help?
do you actually have the chinese font installed on the server, or where php
can access it? you have to specify the font (file) php should use.
Re: Chinese Characters
am 10.10.2007 13:56:41 von StevePBurgess
On 9 Oct, 23:30, "Steve" wrote:
> "Steve" wrote in message
>
> news:1191967493.996319.280550@k79g2000hse.googlegroups.com.. .
>
> > Hi. I need to store chinese characters and Pinyins in a mysql database
> > and then read them from php and using the GD library and
> > imagettftext() function to create an image based on a chinese ttf font
> > of the chinese characters.
>
> > I have tried setting the encoding in the database as UTF-8 and BIG5
> > but the characters display (both in MYSQL and when displayed via PHP)
> > as question marks.
>
> > Can anyone help?
>
> do you actually have the chinese font installed on the server, or where php
> can access it? you have to specify the font (file) php should use.
Yes I do. I am familiar with the use of imagettftext() function. Just
having problems with chinese characters. Guessing it is an encoding
issue but not sure where to start.
Re: Chinese Characters
am 12.10.2007 22:49:20 von Dikkie Dik
Steve wrote:
> Hi. I need to store chinese characters and Pinyins in a mysql database
> and then read them from php and using the GD library and
> imagettftext() function to create an image based on a chinese ttf font
> of the chinese characters.
>
> I have tried setting the encoding in the database as UTF-8 and BIG5
> but the characters display (both in MYSQL and when displayed via PHP)
> as question marks.
>
> Can anyone help?
>
First of all, you need to inform all programs what encoding you use. If
you use utf-8, you need to inform MySQL by sending the command:
SET NAMES utf8;
directly after connection to the database (I know the command has a
misleading name. Look it up in the manual).
Also, you need to inform the browser by sending a header like:
Content-Type: text/html;charset=utf-8
You can do that from php by using the header function, but it is
probably easier to set this in php.ini (two settings: content-type and
charset).
Some text may already in the database and you may not be sure in what
encoding it is stored. To find out, use the mysqldump utility. You can
then open a dump of the table that contains the texts with an
encoding-aware editor.
PHP itself really doesn't care much what encoding is used, as it treats
the strings as binary strings anyway. PHP itself does not show anything
on your screen; that is left to the browser. The only thing you should
be aware of in PHP is the fact that the encoding used has an impact on
the length of the characters. In utf-8, characters may have different
lengths. If you need to work with substrings, there are special string
functions to deal with multibyte encodings.
Good luck!
Re: Chinese Characters
am 13.10.2007 13:45:16 von StevePBurgess
On 12 Oct, 21:49, Dikkie Dik wrote:
> First of all, you need to inform all programs what encoding you use.
Thanks very much for this advice.
My http.conf states that my default character set is UTF-8.
My php.ini has a default charset of utf-8 and a default mime-type of
text/html
I have executed the Set Names command before sending the query to
MySQL.
The output just gives me question marks.
I've obviously missed something. Incidentally, for testing purposes I
am copying and pasting chinese characters from an Excel File (and also
from Chinese sites online). When I paste them into MySQL (using
HeidiSQL) they appear as squares and then, when I move away from the
field, become question marks....
Any thoughts?
Re: Chinese Characters
am 14.10.2007 11:54:28 von Dikkie Dik
> My http.conf states that my default character set is UTF-8.
good, although it is probably not used for php files
>
> My php.ini has a default charset of utf-8 and a default mime-type of
> text/html
Even better. This causes php sites to rendered in utf-8.
> I have executed the Set Names command before sending the query to
> MySQL.
>
> The output just gives me question marks.
The characters may be stored in another encoding by your previous attempts.
> I've obviously missed something. Incidentally, for testing purposes I
> am copying and pasting chinese characters from an Excel File (and also
> from Chinese sites online). When I paste them into MySQL (using
> HeidiSQL) they appear as squares and then, when I move away from the
> field, become question marks....
>
> Any thoughts?
Yes: monitor what's going on. I am going to assume you have a
development database on your local PC.
Reconfigure MySQL to switch on the "query logging". This means that all
queries are written to a log file. Effectively, it allows you to see
what MySQL has done.
For monitoring the log file, I can recommend the freeware version of
BareTail (see http://baremetalsoft.com/ ). It shows the log in real-time
and you can set the encoding to utf-8.
When you have this monitor up and running, do your tests again.
The log file will tell you a lot:
- the connection number is present, so you can see if the SET NAMES
command was executed in the same connection as the INSERT and SELECT
commands. If it was not, the SET NAMES command was not effective.
- You see the actual INSERT end SELECT commands. You will not see
anything special about the select commands because the log file does not
contain the results, but you do see what was inserted using the INSERT
commands.
I can really recommend you to take a look at the output of the mysqldump
utility. You can use it to dump the output of a query if you are afraid
of dumping too much data. If the characters are wrong in the output of
mysqldump, they are wrong in the database as well.
Furthermore, I don't know HeidiSql. You might have to set the encoding
inside that program as well.
Good luck!
Re: Chinese Characters
am 15.11.2007 07:41:54 von StevePBurgess
Thanks for all your advice. I am now in a position where I can get the
chinese characters into MySQL successfully and read them from it with
PHP and display appropriately in the browser (the problem seemed to be
caused by multi-byte characters occupying more "length" in the table.
I had, naively, thought that a VARCHAR of length 3 would be enough to
contain 3 chinese characters. Not so.).
I am now experiencing problems with displaying the characters using
imagettftext().
When I use the cyberbit.ttf font all characters (attempted thus far)
display perfectly.
http://mychinesename.co.uk/createimage.php?type=main&trans=3 &Name=Suzanne
But using fonts located on the internet I get different results
http://mychinesename.co.uk/createimage.php?type=main&trans=3 &Name=Suzanne&font=1
(font wcl-02 from http://www.wazu.jp/gallery/Fonts_ChineseTraditional.html)
http://mychinesename.co.uk/createimage.php?type=main&trans=3 &Name=Suzanne&font=2
(font wts11 from http://www.wazu.jp/gallery/Fonts_ChineseSimplified.html)
With only some of the characters appearing.
Is this likely to be an encoding/character set problem or is it simply
because those characters are not in the character set.
Many thanks, in anticipation
Steve
Re: Chinese Characters
am 15.11.2007 09:51:07 von Bucky Kaufman
"Steve" wrote in message
news:15dde07c-c3a3-449b-93f2-9350b3649ac7@i37g2000hsd.google groups.com...
> When I use the cyberbit.ttf font all characters (attempted thus far)
> display perfectly.
>
> http://mychinesename.co.uk/createimage.php?type=main&trans=3 &Name=Suzanne
>
> But using fonts located on the internet I get different results
Gotta be careful with those TrueType (TTF) fonts.
They're not very web-friendly, and they only ever work just right on
Microsoft Windows.
> With only some of the characters appearing.
>
> Is this likely to be an encoding/character set problem or is it simply
> because those characters are not in the character set.