Question

I have a small ajax application built with php.

Using phpMyAdmin I have set a mysql database to utf-8, and have imported a textfile containing utf-8 data into it.

This worked fine on a windows machine with easyphp, after adding character-set-server=utf8 and default-character-set=utf8 to the my.cnf file.

I have now tried to move this to a production server where I do not have access to the configuration file, and characters such as umlauts are not displayed.

Is there something that can be set in the php code(not the configuration file) to fix this, or some command I can give to mysql?

I tried ALTER DATABASE vweb_50 DEFAULT CHARACTER SET utf8 COLLATE utf8_bin with phpMyAdmin to try from utf8_general_ci but it made no difference.

Was it helpful?

Solution

There's a couple of things to be done here, and I'm not sure I understand your problem correctly, but if I do, I think most of it can be addressed with the PHP functions utf8_encode and utf8_decode:

  • utf8_encode
    • Encodes an ISO-8859-1 string to UTF-8
  • utf8_decode
    • This function decodes data , assumed to be UTF-8 encoded, to ISO-8859-1.

Also, look into htmlentities if needed.

OTHER TIPS

If you use utf-8 throughout the application (Which I would recommend), you don't need utf8_encode/decode functions. Have you checked which encoding your page is served in? Probably the server is configured to send iso-8859-1 as charset, while your test environment sends utf-8. Set the encoding with a Content-Type header:

header("Content-Type: text/html; charset=utf-8");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top