简体   繁体   English

汉字问题

[英]problem with chinese character

We can store Chinese character into mysql table Using this 我们可以将汉字存储到mysql表中

(" meta http-equiv="Content-type" value="text/html; charset=UTF-8" ") (“ meta http-equiv =” Content-type“ value =” text / html; charset = UTF-8“ ”)

at the top of the page and taking Chinese character through input box manually easily, it works OK and store Chinese character into mysql table like this(" A #20026; A #24744; A #20026; A #24744;"). 在页面顶部,可以轻松地通过输入框手动输入汉字,它可以正常工作并将汉字存储到mysql表中,如下所示(“ A #20026; A #24744; A #20026; A #24744;”)。
But when read Chinese char from an excel file using php and want to insert in mysqltable with php then it stores like this 但是,当使用php从excel文件中读取中文字符并想用php插入mysqltable时,它会像这样存储

("上海东渡船舶管ç†æœ‰é™å…¬å¸") (“ 上海东渡船舶管ç†æœ‰é™å…¬å¸”)

This is also working fine with the help of php header function ["header('Content-type: text/html; charset=UTF-8') ;"] without http header it is no working. 在没有HTTP标头的情况下,借助php标头功能[“ header('Content-type:text / html; charset = UTF-8');”],此方法也可以正常工作。 But I want to store chinese char like above(" A #20026; A #24744; A #20026; A #24744;") in mysql table. 但是我想像上面那样存储中文字符(“ A #20026; A #24744; A #20026; A #24744;”)在mysql表中。

Note:= Where u see "A" in code there is " ampersand " sign. 注意:=在代码中看到“ A”的地方有“ ”号。 If i write " ampersand " there then it will display as chinese character, so here noticed. 如果我在此处写“ ”,它将显示为汉字,因此请注意。

Any one can help me ? 有人可以帮助我吗? Help should be happily. 帮助应该很愉快。 Thanks. 谢谢。 Have a nice day... 祝你今天愉快...

You should retag your question from SQL to Excel. 您应该将问题从SQL重新标记为Excel。 Apparently, it is not related to mysql. 显然,它与mysql没有关系。 Problem is the part where you read Excel file in PHP. 问题是您在PHP中读取Excel文件的部分。 You get corrupted data from Excel file and then it is too late to do anything. 您从Excel文件中获取了损坏的数据,然后为时已晚。

Does library you use to read Excel files understand unicode characters at all? 您用来读取Excel文件的库是否完全理解Unicode字符? Do PHP understand unicode or is that library at least able to send unicode characters in utf-8? PHP是否了解unicode或该库至少能够在utf-8中发送unicode字符? I don't think so. 我不这么认为。 (UTF-8 strings can work correctly in scripting environments where unicode isn't actually supported, because the program only transfers the string from user to database and vice versa.) (UTF-8字符串可以在实际上不支持unicode的脚本环境中正常工作,因为该程序仅将字符串从用户传输到数据库,反之亦然。)

The characters are not stored as UTF-8 in your excel file then and have to be transcoded. 字符然后不以UTF-8格式存储在excel文件中,必须进行转码。

See utf8_encode 参见utf8_encode

在MySQL_connect之后尝试:

mysql_query("SET NAMES 'utf8'");

You should first make sure, that the Database-Table and the Form, where the User enters the characters, are both UTF-8. 首先,应确保用户输入字符的数据库表和表单均为UTF-8。 Also notice, that many PHP-Functions don't support UTF-8 . 还要注意, 许多PHP函数不支持UTF-8 If you are using functions like htmlentities() , make sure you replace them by Multibyte-String-secure functions ( mb_ ). 如果您使用的是htmlentities()类的函数,请确保将其替换为多字节字符串安全函数( mb_ )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM