473,785 Members | 2,307 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7600

"Steve" <St***********@ gmail.comwrote in message
news:11******** **************@ k79g2000hse.goo glegroups.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.goo glegroups.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=ut f-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
4768
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: <%@ page pageEncoding="UTF-8" %> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
6
22274
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 header, I found "zh" is not standard. I found this line in apache2's default httpd.conf # Simplified Chinese (zh-CN) AddLanguage zh-CN .zh-cn
8
3489
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 solve it ?? Private Sub Init() With AMSXML ..Formatting = Formatting.Indented ..Indentation = 4 ..IndentChar = " " ..WriteStartDocument()
8
11989
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 part of a datagrid. When an input textbox is displayed it does not display chinese characters, but rather the unicode characters stored in the mssql 2000 server backend.
4
6902
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 the data in a node. The CString was then display in CListCtrl. For the traditional chinese characters, they were shown correctly, but for simplified characters, I encounted many "?", but some characters were correct.
1
2037
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 the tables. However, I am not able to enter Chinese characters in the VBA editor. Do I need to install Chinese Windows? Do I need to install Chinese version of Microsoft Access? Are there any websites I need to visit to get educated? Am I in...
0
3714
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 table where i want to import the data using "load data local infile" has collation utf8_unicode_ci. but after the import is done, the chinese characters are converted into so strange characters. to show the chinese symbols in a php-script i use...
5
8561
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 I can type characters into this box no problem. They display correctly. I can also copy and paste Chinese characters from web sites into this text box and they display no problem. Here is my problem. If I put some Chinese characters in the...
2
6296
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 to be able to detect which characters are latin based and which are chinese ideographs. eg) a user may enter "hello ÐÂÎÅÍø world" this is because many Chinese search phrases (especially those involved with technology may include English words...
2
6725
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 of Chinese characters, on my machine I installed language pack and currently set language as Chinese PRC but still it's not working. Option Explicit Private Type DOCINFO pDocName As String pOutputFile As String pDatatype As String
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10162
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2893
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.