1

I'm having a problem in inserting data in php. It sometimes create a character like a black diamond with a question mark. enter image description here

do you have any idea how can i fix it?

123
  • 278
  • 2
  • 4
  • 19
  • Looks like you are not encoding the characters properly. Check that your database/table collation is `UTF-8` to begin with. – Nadh Apr 30 '12 at 10:21
  • What is current character encoding? Did you performed any manipulations with text (split, substr, regex, etc.)? – Scorpil Apr 30 '12 at 10:22
  • http://stackoverflow.com/questions/275411/php-output-showing-little-black-diamonds-with-a-question-mark – arun Apr 30 '12 at 10:26

1 Answers1

2

You should have the same encoding everywhere and define it.

Define the charset like this;

<meta charset="UTF-8" />

and in the header;

header('Content-Type: text/html; charset=utf-8');

You can also write your characters with html characters, however it is always good to define the charset.


If you have ISO-8859-1(latin1) data in your database, and the rest of the site in UTF-8. Then define the charset-tag as above and use the function utf8_encode() to give the string a properly encoding. There is also a reverse function called utf8_decode()

Mattias
  • 9,211
  • 3
  • 42
  • 42