Jump to content

Recommended Posts

Hi, when I enter a Chinese name in PHP, it returns  Incorrect string value: '\xC2\xED\xC8\xD9' for column 'm_name' at row 1.

But if I enter the same Chinese character using phpMyAdmin, it was okay and the value stored for the same Chinese character is 马&#33635

This is an old program and it worked fine all along. But after I reinstall Apache, PHP, MySql, I started having this problem.  But if I import (except for this field) other data with Chinese character into the new database, there was no problem. 

This field m_name has a varchar size of 20.

I don't know what's wrong with it.  Can anyone help??

Thanks.

 

 

Link to comment
https://forums.phpfreaks.com/topic/94215-language-conversion-problem-in-php/
Share on other sites

I can help you with this as I program Japanese sites, and the issues are basically the same.

 

Its a huge pain in the butt though.

 

There are a few things you have to do to display chinese characters properly with php:

 

The first thing is, I don't believe that gb2312 will work for you. The reason for this being that it doesn't appear to be supported by php mbstring functions. I would suggest using EUC-CN, as php seems to deal well with the EUC charsets.

 

1) Set the collocation of the database to the EUC-CN

2) Enable the mbstring (multibyte string) library in php.ini

3) Again in php.ini, you need to set the internal charset to EUC-CN. You also need to set the output charset to mbstring to EUC-CN (You could also set it to BIG5 if you want. But don't use this for the internal encoding, because according to php.net:

 

It's highly discouraged to use SJIS, BIG5, CP936, CP949 and GB18030 for the internal encoding unless you are familiar with the parser, the scanner and the character encoding.

http://jp.php.net/mbstring

 

So stick with EUC-CN for the internal encoding).

4) Set the default language for the MB string functions to Chinese.

 

Your php.ini should now look like this:

 

edit: phpfreaks won't let me attach the code, as it is php.ini code. So I am attaching a document to this post that has the settings you need.

 

4) Set a meta tag in the head of your document to read as follows:

 

edit: I couldn't include this code either, so I put it in the attached text document as well.

 

Finally, you need to save your document in EUC-CN encoding. You should be able to do this by choosing 'save as' and selecting the charset, however some editors don't have all charsets available. If that is the case, you need to start using a different editor. If you don't, any static text hard coded into your documents will not display properly.

 

Good luck!

I checked my php.ini file both in the php directory and in the Apache directory.  Found that mbstring was set to Japanese (don't ask me why, I did not do it) and internal charset set to EUC-JP.  I modified these two setting to Chinese and EUC-CN (again in both directory) and when I invoked the same page again in DW, I got HTTP 500 (page cannot be displayed).  After I copied the original php.ini file back, restart again, I still can't get the page to display. Any idea??  Appreciate if you could email me the code including the meta tag, my email address is [email protected].

 

Thanks.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.