-2

I have a database that I run using MySql and codeigniter that has a mix of english and french names in it.

The french names, like Andrée, come back as Andrée, and other various obviously incorrect.

How do I prevent this from happening, and that we can put in Andrée and get Andrée back?

Thanks!

JonYork
  • 1,223
  • 8
  • 31
  • 52

2 Answers2

0

If your database settings are set to UTF-8 (and by the sound of your comments they are), you may be seeing these strange characters because your page is not rendering as UTF-8.

UTF-8 documents are supposed to come with a Content-Type header to say what encoding they should be parsed as. To add this header you can add the following code either before or after your view/s get loaded:

$this->output->set_content_type('text/html; charset=utf-8');

In your document's you should add the following line:

<meta charset="utf-8">

If you are rendering text only then you will want to change the part of the header where it says text/html to something more appropriate such as text/plain.

Andrew Gould
  • 376
  • 1
  • 9
  • I looked at the database value in Phpmyadmin, it has the proper accent and spelling, so it's now Codeigniter side problems. This has been in my header for all my views " " Nothing changes when I put "$this->output->set_content_type('text/html; charset=utf-8');" in the controller right before I load the view. – JonYork Feb 10 '15 at 13:02
  • It should logically be working, but without seeing the full setup I would recommend simply using the function `htmlentities()` (http://php.net/htmlentities) for displaying the UTF-8 names. The code delivered to the browser should then be showing `Andrée` instead of `Andrée`. – Andrew Gould Feb 10 '15 at 22:41
-1

Turns out, I had to tell php that utf-8 was the default in the config file. All is well since then!

JonYork
  • 1,223
  • 8
  • 31
  • 52