简体   繁体   中英

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. The database is coded with 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)

I tried using $msqli->set_charset("utf8"); when connecting, utf8_encode with the strings, but nothing, it still shows strange characters.

Thanks in advance

You need to use UTF8 the whole way. 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. Otherwise you need to convert to whatever charset you use on the page before printing the strings.

My advice is to use UTF8 everywhere . 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! Check this

http://www.unicodetools.com/

Strangely, after a lot of tries, what it made codification work was "utf8_decode". I don't know exactly what the problem was, but now is solved!

Thanks for your answers!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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