473,320 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Chinese Characters

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?

Oct 9 '07 #1
6 7553

"Steve" <St***********@gmail.comwrote in message
news:11**********************@k79g2000hse.googlegr oups.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.
Oct 9 '07 #2
On 9 Oct, 23:30, "Steve" <no....@example.comwrote:
"Steve" <StevePBurg...@gmail.comwrote in message

news:11**********************@k79g2000hse.googlegr oups.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.

Oct 10 '07 #3
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!
Oct 12 '07 #4
On 12 Oct, 21:49, Dikkie Dik <dik...@nospam.orgwrote:
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?

Oct 13 '07 #5
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!
Oct 14 '07 #6
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/createima...3&Name=Suzanne

But using fonts located on the internet I get different results

http://mychinesename.co.uk/createima...Suzanne&font=1
(font wcl-02 from http://www.wazu.jp/gallery/Fonts_Chi...aditional.html)

http://mychinesename.co.uk/createima...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
Nov 15 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jeff | last post by:
Having a problem displaying both german and chinese characters from a UTF-8 database on the same *.jsp page. Can make Chinese characters appear correctly by including the following lines: <%@...
6
by: Zhang Weiwu | last post by:
Hello. I am working with a php software project, in it (www.egroupware.org) Chinese simplified locate is "zh" while Traditional Chinese "tw". I wish to send correct language attribute in http...
8
by: Agnes | last post by:
In my .net ,i need to generate an xml file , however, user may input a chinese character, Then , the xml will got something unknow characters. the following is my code, Does anyone know how to...
8
by: pabv | last post by:
Hello all, I am having a few issues with encoding to chinese characters and perhaps someone might be able to assist. At the moment I am only able to see chinese characters when displayed as...
4
by: K | last post by:
I've an XML file in UTF-8. It contains some chinese characters ( both simplified chinese and traditional chinese). In loading the XML file with MSXML parser, I used the below code to retrieve...
1
by: paulineliu | last post by:
Hi, I would like to develop access databases for Chinese companies. I have microsoft access 2002 in windows XP. I am able to create labels in Chinese characters and enter Chinese characters in...
0
by: st.frey | last post by:
I've got a problem with importing chinese characters into a mysql-table and have read several mailings but didn't find a solution. i have a utf-8 text file that contains chinese characters. the...
5
by: Figmo | last post by:
I'm having a problem working with foreign characters (well....foreign to me anyway) I have a textbox control on a form. The font is set to MS Arial Unicode. If I use the Chinese input method...
2
by: Wassy | last post by:
Hi, i have a website which contains both chinese and english content which is stored in a database. Each record in the dB has an english and Chinese field. If a user enters a search string i have...
2
by: Flying Kite | last post by:
Hi All, I want to know how to print chinese characters on Zebra Printer, following code working fine with English string, but it's not working for Chinese string. It shows ASCII characters instead...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.