Chinese Characters

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve

    #1

    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?

  • Steve

    #2
    Re: Chinese Characters


    "Steve" <StevePBurgess@ gmail.comwrote in message
    news:1191967493 .996319.280550@ 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.


    Comment

    • Steve

      #3
      Re: Chinese Characters

      On 9 Oct, 23:30, "Steve" <no....@example .comwrote:
      "Steve" <StevePBurg...@ gmail.comwrote in message
      >
      news:1191967493 .996319.280550@ 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.

      Comment

      • Dikkie Dik

        #4
        Re: Chinese Characters

        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!

        Comment

        • Steve

          #5
          Re: Chinese Characters

          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?

          Comment

          • Dikkie Dik

            #6
            Re: Chinese Characters

            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!

            Comment

            • Steve

              #7
              Re: Chinese Characters

              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.



              But using fonts located on the internet I get different results


              (font wcl-02 from http://www.wazu.jp/gallery/Fonts_Chi...aditional.html)


              (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


              Comment

              Working...