简体   繁体   English

Mysql Utf-8和PHP

[英]Mysql Utf-8 and PHP

I hate characters sets and everything related, they make me get headaches!! 我讨厌字符集和所有相关的东西,它们让我头疼!

I'm now working on an app for using with OpenCart. 我现在正在开发与OpenCart一起使用的应用程序。 The database is coded with utf8-bin. 该数据库使用utf8-bin编码。

What I want to do with my app in PHP is take data from an XML (encoded in ISO-8859-1) and put it correctly on the DB (encoded in UTF8-BIN) 我想在PHP中使用我的应用程序要做的是从XML(以ISO-8859-1编码)中获取数据,然后将其正确地放置在DB(以UTF8-BIN编码中)中

I tried using $msqli->set_charset("utf8"); 我尝试使用$ msqli-> set_charset(“ utf8”); when connecting, utf8_encode with the strings, but nothing, it still shows strange characters. 在连接时,utf8_encode与字符串连接,但是什么也没有,它仍然显示奇怪的字符。

Thanks in advance 提前致谢

You need to use UTF8 the whole way. 您需要整个使用UTF8。 You are right about connecting to MySQL with UFT8, but you must also convert the file after reading it, and make sure you have UTF8 specified in the HTML page, in the header with <meta http-equiv="content-type" content="text/html;charset=utf-8" /> , or in the HTTP header. 使用UFT8连接到MySQL是正确的,但是在读取文件后还必须转换文件,并确保在HTML页面中的<meta http-equiv="content-type" content="text/html;charset=utf-8" />标头中指定了UTF8。 <meta http-equiv="content-type" content="text/html;charset=utf-8" />或在HTTP标头中。 Otherwise you need to convert to whatever charset you use on the page before printing the strings. 否则,在打印字符串之前,您需要转换为页面上使用的任何字符集。

My advice is to use UTF8 everywhere . 我的建议是在所有地方都使用UTF8。 Then you'll avoid a lot of the problems. 然后,您将避免很多问题。

You have to convert the XML from ISO to UTF before you put it into the DB! 在将XML放入数据库之前,必须将XML从ISO转换为UTF! Check this 检查一下

http://www.unicodetools.com/ http://www.unicodetools.com/

Strangely, after a lot of tries, what it made codification work was "utf8_decode". 奇怪的是,经过大量尝试,使编码工作成功的是“ utf8_decode”。 I don't know exactly what the problem was, but now is solved! 我不知道到底是什么问题,但是现在解决了!

Thanks for your answers!! 感谢您的回答!

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

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